I am newbie to asp.net mvc. I have searched a lot for the following situation but couldn't find anything in c#. Please don't block me. Kindly just provide a solution because I want to learn.
Employee_table (which shows active employees with following attributes)
1.1 id , name , total_due_amount , Status
transaction_table (which contain all transaction for all employees with following attributes)
2.1 id , parent_id , date , labor_cost_of_week , paid , due , details
Employee controller
Employee_transaction controller
where parent id is foreign key from Employee_table I need to show the due amount of last transaction in employee table for all employees.
Feel free to ask anything in case I didn't explain.
First of all you need to figure out the exact formula which is used for the calculation. Afterwards, collect necessary data from all database and make those calculations, then return your answer.
There is probably a more sophisticated way to do this, but for you the simplest one is the best.
Basically, you send request to the controller, the method in controller accesses some other class containing all the methods for calculations and then you return a string or JSON result with the controller.
Related
I've started working on a web application project, where a feature is: the admin user can create/update few custom forms choosing different input types from the database and the end users can update the form data in a repetitive fashion/sometimes daily and the data stores in the database for further use cases. To elaborate, the admin user can choose any of "checkbox", "textbox", "textarea", "datetime", "temperature" etc. input types and create a form. The end user then can read the form and input the values that is to be saved in the database for reporting to admin.
I need to use ASP.NET Core MVC, SQL, EF, code first migration at the back-end of the project.
I am thinking maybe (as an example) a Form model with Id and Name properties, TextBox model with Id, Name, FormId, DateTime model with Id, Name, FormId etc. for creating the forms and then when user inputs values that can be updated using other models/tables in the database like TextBoxRecord model with Id, TextBoxId, Value, UserId, DateEntered etc. But then it will be too many tables to update and read every time when entering values and displaying reports to the admin.
I appreciate any help with a good design idea of the data model or how to attain this kind of logic. Also feel free ask, if you have any questions. Thanks.
Some time ago, I was working on some simular project. We don't store each of our form field in DB, because we don't want to update DB each time we need to add some new-kind-of-form-field. We believe it's up to HTML+JS to decide what kind of input to use with particular object property.
We create a serializer, that serialize form structure in xml and store it in DB. In this xml we keep a TableName (EF DataSet<> name) and ColumnName (name of model property) for each FormField.
When we need to show a form to user, we deserialize it from DB, pack in ViewModel (because we don't want to show to user real names of our DB tables) and send it to JavaScript code as JSON. JS then constructs the form element and show it to user. When user submits the data, we again deserialize corresponding form from DB and update actual models in db with data from user input.
Hope this will help.
To all the, eurhm, people, who find this an interesting question and "would like to know the answer too", there's an interesting article to read at
https://www.red-gate.com/simple-talk/opinion/opinion-pieces/bad-carma/
That story started with (at least as good as) exactly the same kind of user requirement as the OP's here.
(And to those who want to downvote this because "not an answer" : it is MORE of an answer because it shows in intimate detail WHY you NEVER want to even start going down that alley.)
We were working on a project that would pass our e-commerce orders into Acumatica through Web Service API.
As part of the order process, we need to search through Customers to get the one we need, and then we want to have ability to make change to this customer data based on primary key, i.e. BAccountID; however, when I used Web Service API "AR303000Export" to get customer info, I didn't see "BAccountID" in the data that I was getting from Acumatica, therefore I couldn't update that Business Account record based on primary keys (BAccountID and CompanyID, we already have CompanyID).
Is there anyway to get primary key values when doing search through Web Service API?
I noticed I might be able to use "AcctCD", which is called "Customer ID" to update, however, I'm not sure whether that Customer ID is unique or not in database, since it is not specified as Primary key...
Any help would be really appreciated.
Thanks.
Your specific question is how to get BAccountID, and you can - so I'll answer that question. But you probably do want to work with AcctCD.
This snippet of code builds the command list for AR303000Export
var commandgroup = new Command[]
{
AR303000Schema.CustomerSummary.ServiceCommands.EveryCustomerID
, WSTools.NewA4Field(AR303000Schema.CustomerSummary.CustomerID.ObjectName, "DefContactID")
, AR303000Schema.CustomerSummary.CustomerID
, AR303000Schema.CustomerSummary.CustomerName
, WSTools.NewA4Field(AR303000Schema.CustomerSummary.CustomerID.ObjectName, "BAccountID")
, WSTools.NewA4Field(AR303000Schema.CustomerSummary.CustomerID.ObjectName, "Type")
,AR303000Schema.CustomerSummary.Status
, AR303000Schema.GeneralInfoMainContact.Phone1
, AR303000Schema.GeneralInfoMainContact.Phone2
, WSTools.NewA4Field(AR303000Schema.GeneralInfoMainContact.Phone1.ObjectName, "Phone1Type")
, WSTools.NewA4Field(AR303000Schema.GeneralInfoMainContact.Phone1.ObjectName, "Phone2Type")
WSTools.NewA4Field(AR303000Schema.CustomerSummary.CustomerID.ObjectName, "LastModifiedDateTime")
};
You'll notice that some interesting things are just not exposed in the strongly typed schema, but still available if you know how to build the command to reference the field. (Such as the type of phone number in Phone1 being in Phone1Type).
In your case, you need a command to export BAccountID from the same internal object name as CustomerID:
WSTools.NewA4Field(AR303000Schema.CustomerSummary.CustomerID.ObjectName, "BAccountID")
in your export command list. (it is 5th in the snippet above).
There are many ways to build the "Field" object - I have a utility method for that:
public static AcumaticaWS.Field NewA4Field(string objName, string fldName)
{
AcumaticaWS.Field nv = new AcumaticaWS.Field();
nv.ObjectName = objName;
nv.FieldName = fldName.TrimEnd();
return nv;
}
Hope this helps!
I wrote an windows form app in c# that makes a presence/delay log for employees and now I'm trying to add a feature to that app which does the following :
Takes the log of that day (who is present and who came late to work) from it's database and assign it to the date of that day, so i'd be able to view one each separate day who was present and who came late to work.
To make it more clear :
Workers table : where 1 means the employee is present or delayed
ID--name----------presence-----delay
1--sam--------------1----------0---
2--jack-------------0----------0---
3--ted--------------1----------1---
Date table :
Day---------------present----delay-----absent
14/10/2012---------sam--------ted-------jack
------------------------ted-----------------------
and so on, i hope i made my idea clear.
how will the second table look like and how will the relation be ?
how will i view the result like the one in the date table ?
--Person-- --Presence-- --Delay--
ID ID ID
Name Date Date
// other info PersonID PersonID
IsPresent
First of all, you should hold Person table separately and use it's ID in other tables. I strongly recommend reading about data redundancy and database normalization. PersonID in the other tables refer to ID in Person table.
I think Presence should be logged for each day. Delay should be logged if only the Person shown up late that day.
you may want to do something like this, may not be 100% but should get you going in the right direction. Run into any other questions let me know will help as i can
table: Employees { Id, Name }
table: Logs {EmployeeId, DateCreated, OnTime (bit false if late)}
select Name
Status = CASE WHEN OnTime = 1 THEN "On Time"
WHEN OnTime is null THEN "Absent"
ELSE "Late"
from Employees as e
left join Logs as l
on e.Id = l.EmployeeId
Where l.DateCreated = #aDate
or l.DateCreated is null
to show the data the way you are looking to would then become a task for the report engine or a pivot table depending on the requirements
I've developed an application for a client with the following relationship:
A SalesOrder has a foreign key relationship to a Customer (one-to-one).
The client now wants to be able to delete Customers so that they won't be available for any future (new) SalesOrders, but obviously I would like to retain the historical records for reporting, etc. Likewise, the record may need to be update-able in the future in rare cases, so in "Edit" mode the customer would need to be there (but ALL other deleted Customers would not)
I am looking for input on a pattern to model this, or better recommendations. My thought was to have an "Archived" bit on the Customer, but my problem is that if someone loads up an old SalesOrder I would also need to load that archived record for the DropDownList that Customers populate.
Since I'm using Entity Framework and an EntityDataSource, my guess is that I might get a runtime exception on the SelectedValue bind of the DropDownList also, but I haven't verified this.
Any thoughts or recommendations on where to start?
Thank you.
I believe I have a solution. I've been racking my brain on it all day but I think it's fairly easy. In a quick prototype it appears to do what I need it to:
I added an "Archived" bit to the Customers table (actually to the BusinessEntity table they inherit from). Then for the "Edit Sales Order" page, when querying Customers, I have a where clause which includes the customer by ID.
For example (pseudocode):
SELECT CustomerID, Name FROM Customers WHERE Archived = 0 OR CustomerID = 52
That pulls all the active customers and the one customer for the record that I need. This allows the customer to still be linked to the record for editing AND doesn't generate a runtime exception with the DropDownList binding.
For reporting, I assume I'll just not filter based on the Archived bit since it's all read-only anyway.
I have metadata in a DB table that i want to use in code.
The metadata is different sorts of Time types for reporting spent time.
The data can be:
NormalTime
OverTime
Vacation
Illness
etc
The data have a ID and a description and some other stuff.
ID = 1
Name = "Regular time"
Description = "Normal work time"
What is a good way to relate to this data in my code?
If for example i want create a method that sums all the NormalTime reported (i have another table that stores used time where the NormalTime ID and amount and some other stuff) how do i do that?
I dont want to hardcode the ID:
Select * from xyz where TimeType = 1
What i wanna do is:
Select * from xyz where TimeType = NormalTime.
Otherwise the code becomes very hard to read.
In my current solution i have hardcoded string consts that correlates to the ID.
The problem with this is if someone changes the description of the TimeType from NormalTime to something eles the hardcoded string const sais one thing and the db data sais something else.
And yes, this has happend as i dont have control over the DB content :(
So, how do I solve this in the best maintainable and readable way where changes can occur in the DB table and the code dont get very hard to read.
Where someone can add TimeTypes to the DB and later I can add methods that uses them in code.
One way to do this would be to use Visual Studio's T4 text generation templates.
(Entity Framework uses these for its code generation)
You can create a template file which contains code to pull the tables with metadata
from the database, and generates classes with static constants in.
They do need to be run whenever the database changes, though. But I think you might be able
to set them up so they do re-generate every time your code is built.
A question about T4 templates
You could have an enum type on the C# side that maps to a table in the database.
http://www.codeproject.com/Articles/41746/Mapping-NET-Enumerations-to-the-Database