public bool Save(ModelStateDictionary modelState, int userID, int employeeID) { if (!Validate(modelState)) { return(Result = false); } QueryOutput queryResult; var query = ""; var action = ""; var id = ID.ToString(); if (!StartDate.HasValue) { StartDate = DateTime.Now; } if (ID > 0) { query += String.Format( @"update Employee set Name = N'{0}', Address = N'{1}', Phone = N'{2}', Position = N'{3}', Image = N'{4}', BussinessID = {5}, StoreID = {6}, StartDate = {7}, WorkTime = N'{8}', MonthlySale = {9}, BaseSalary = {10}, AdditionalSalary = {11}, WorkDays = {12}, OffDays = {13}, Summary = N'{14}', EndDate = {16}, BankNumber = N'{17}', BankName = N'{18}', BankBranch = N'{19}', WorkStatus = N'{20}', DOB = {21} where ID = {15}", new object[] { Name, Address, Phone, Position, Image, BussinessID, StoreID.DbValue(), StartDate.DbValue(Constants.DatabaseDateString), WorkTime, MonthlySale, BaseSalary, AdditionalSalary, WorkDays, OffDays, Summary, ID, EndDate.DbValue(Constants.DatabaseDateString), BankNumber, BankName, BankBranch, WorkStatus, DOB.DbValue(Constants.DatabaseDateString) }); if (LoginID > 0) { query += String.Format(" update Login set EmployeeID = {0} where ID = {1}", ID, LoginID); } else { query += String.Format(" update Login set EmployeeID = null where EmployeeID = {0}", ID); } action = DbAction.Employee.Modify; } else { query += String.Format(@"declare @ID table (ID int) insert Employee(Name, Address, Phone, BussinessID, StoreID, Position, Image, StartDate, WorkTime, MonthlySale, BaseSalary, AdditionalSalary, WorkDays, OffDays, Summary, Status, EndDate, BankNumber, BankName, BankBranch, WorkStatus, DOB) output inserted.ID into @ID values (N'{0}', N'{1}', N'{2}', {3}, {4}, N'{5}', N'{6}', {7}, N'{8}', {9}, {10}, {11}, {12}, {13}, N'{14}', 'active', {15}, N'{16}', N'{17}', N'{18}', N'{19}', {20})", new object[] { Name, Address, Phone, BussinessID, StoreID.DbValue(), Position, Image, StartDate.DbValue(Constants.DatabaseDateString), WorkTime, MonthlySale, BaseSalary, AdditionalSalary, WorkDays, OffDays, Summary, EndDate.DbValue(Constants.DatabaseDateString), BankNumber, BankName, BankBranch, WorkStatus, DOB.DbValue(Constants.DatabaseDateString) }); id = "(select top 1 ID from @ID)"; if (LoginID > 0) { query += String.Format(" update Login set EmployeeID = (select top 1 ID from @ID) where ID = {0}", LoginID); } action = DbAction.Employee.Create; } Result = Execute(new DbQuery(userID, employeeID, action, query, true, id, "Name"), out queryResult); if (Result) { Messages = new List <string>() { "Lưu thông tin thành công" } } ; return(Result); }