public ActionResult Create([Bind(Include = "Name,Username,Password,Type")] User user)
        {
            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem {
                Text = "Admin", Value = "Admin", Selected = true
            });
            items.Add(new SelectListItem {
                Text = "Local", Value = "Local"
            });
            ViewBag.TypeList = new SelectList(items, "Value", "Text", "Admin");
            if (ModelState.IsValid)
            {
                var check = db.Users.Any(x => x.Username == user.Username);
                if (check)
                {
                    ViewBag.ErrorMessage = "Username already Exists.";
                    return(View(user));
                }
                else
                {
                    if (user.Type == "Local")
                    {
                        user.SuperPassword = null;
                    }
                    user.CreatedBy = Session["LoggedIn"].ToString();
                    user.CreatedOn = DateTime.Now;
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(user));
        }
        public ActionResult Create([Bind(Include = "MachineNumber,Type,IsActive")] Machine machine)
        {
            if (ModelState.IsValid)
            {
                var m = db.Machines.Where(x => x.MachineNumber == machine.MachineNumber).Count();
                if (m > 0)
                {
                    List <SelectListItem> macTypes = new List <SelectListItem>();
                    var mts = db.MachineTypes.Distinct().ToList();
                    foreach (var t in mts)
                    {
                        macTypes.Add(new SelectListItem()
                        {
                            Text = t.MType, Value = t.MType
                        });
                    }
                    if (mts.Count > 0)
                    {
                        ViewBag.TypeList = new SelectList(macTypes, "Value", "Text", macTypes[0]);
                    }
                    else
                    {
                        ViewBag.TypeList = new SelectList(macTypes, "Value", "Text");
                    }
                    ViewBag.ErrorMessage = "Machine number already exists";
                    return(View(machine));
                }
                else
                {
                    machine.CreatedBy = Session["LoggedIn"].ToString();
                    machine.CreatedOn = DateTime.Now;
                    db.Machines.Add(machine);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            List <SelectListItem> machineTypes = new List <SelectListItem>();
            var mt = db.MachineTypes.Distinct().ToList();

            foreach (var t in mt)
            {
                machineTypes.Add(new SelectListItem()
                {
                    Text = t.MType, Value = t.MType
                });
            }
            if (mt.Count > 0)
            {
                ViewBag.TypeList = new SelectList(machineTypes, "Value", "Text", machineTypes[0]);
            }
            else
            {
                ViewBag.TypeList = new SelectList(machineTypes, "Value", "Text");
            }
            return(View(machine));
        }
Пример #3
0
        public IActionResult Post([FromBody] GasStation station)
        {
            if (station == null)
            {
                return(BadRequest());
            }

            db.Station.Add(station);
            db.SaveChanges();
            return(Ok(station));
        }
Пример #4
0
        public ActionResult Create([Bind(Include = "CompanyName,ContactNo,Dealer,CNIC,Address")] Company company)
        {
            if (ModelState.IsValid)
            {
                company.CreatedBy = Session["LoggedIn"].ToString();
                company.CreatedOn = DateTime.Now;
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
        public ActionResult Create([Bind(Include = "Id,RateDate,FuelType,RateValue")] Rate rate)
        {
            if (ModelState.IsValid)
            {
                rate.AddedBy = Session["LoggedIn"].ToString();
                rate.AddedOn = DateTime.Now;
                db.Rates.Add(rate);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rate));
        }
Пример #6
0
        internal static bool StaticNewTransaction(Transaction newTransaction)
        {
            if (TransactionExist(newTransaction))
            {
                throw new InvalidOperationException("TRANSACTION_REFERENCE_ALREADY_EXIST");
            }

            if (newTransaction.TransactionDate < DateTime.Today.AddDays(-1))
            {
                throw new InvalidOperationException("TRANSACTION_DATE_NOT_VALIDE");
            }

            using (var db = new StationContext())
            {
                newTransaction.TransactionGuid = newTransaction.TransactionGuid == Guid.Empty ? Guid.NewGuid() : newTransaction.TransactionGuid;
                var transDate = newTransaction.TransactionDate.GetValueOrDefault();
                newTransaction.TransactionDate = new DateTime(transDate.Year, transDate.Month, transDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                if (string.IsNullOrEmpty(newTransaction.Description))
                {
                    newTransaction.Description = newTransaction.Designation;
                }

                newTransaction.DateAdded        = DateTime.Now;
                newTransaction.AddUserGuid      = Guid.Empty;
                newTransaction.LastEditDate     = DateTime.Now;
                newTransaction.LastEditUserGuid = Guid.Empty;

                db.Transactions.Add(newTransaction);
                return(db.SaveChanges() > 0);
            }
        }
Пример #7
0
        public async Task <bool> Post(Fuel myFuel)
        {
            using (var db = new StationContext())
            {
                if (myFuel.FuelGuid == Guid.Empty)
                {
                    myFuel.FuelGuid = Guid.NewGuid();
                }

                myFuel.DateAdded    = DateTime.Now;
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Add(myFuel);
                if (!myFuel.Prices.Any())
                {
                    return(db.SaveChanges() > 0);
                }

                if (myFuel.Prices.First().PriceGuid == Guid.Empty)
                {
                    myFuel.Prices.First().PriceGuid = Guid.NewGuid();
                }
                myFuel.Prices.First().ProductGuid = myFuel.FuelGuid;
                myFuel.Prices.First().FromDate    = DateTime.Now;
                db.Set <Price>().Add(myFuel.Prices.First());

                return(await db.SaveChangesAsync() > 0);
            }
        }
Пример #8
0
        /// <summary>
        /// Represente un client
        /// </summary>
        /// <param name="newCustomer"></param>
        /// <exception cref="InvalidOperationException">CAN_NOT_CREAT_STAFF_PROFILE</exception>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.CustomerWrite)]
        public bool AddCustomer(Customer newCustomer)
        {
            Guard.WhenArgument(newCustomer.Person.FullName, "CUSTOMER_NAME_CAN_NOT_BE_EMPTY").IsNullOrEmpty().IsEqual("Inconnue").Throw();

            using (var db = new StationContext())
            {
                if (newCustomer.CustomerGuid == Guid.Empty)
                {
                    newCustomer.CustomerGuid = Guid.NewGuid();
                }
                if (newCustomer.Person.PersonGuid == Guid.Empty)
                {
                    newCustomer.Person.PersonGuid = Guid.NewGuid();
                }

                // ReSharper disable once PossibleNullReferenceException
                var userTrace = (Guid)Membership.GetUser().ProviderUserKey;
                newCustomer.DateAdded        = DateTime.Now;
                newCustomer.AddUserGuid      = userTrace;
                newCustomer.LastEditDate     = DateTime.Now;
                newCustomer.LastEditUserGuid = userTrace;

                db.Set <Person>().Add(newCustomer.Person);
                db.Customers.Add(newCustomer);
                return(db.SaveChanges() > 0);
            }
        }
Пример #9
0
        /// <summary>
        /// Creer Nouvelle Conversation
        /// </summary>
        /// <param name="newChat"></param>
        /// <returns></returns>
        public bool SaveChat(Chat newChat)
        {
            using (var db = new StationContext()) {
                if (newChat.Persons.Count < 2)
                {
                    throw new InvalidOperationException("CONVERSATION_MUST_HAVE_AT_LEAST_TWO_PERSONS");
                }

                if (newChat.ChatGuid == Guid.Empty)
                {
                    newChat.ChatGuid = Guid.NewGuid();
                }

                newChat.DateAdded        = DateTime.Now;
                newChat.AddUserGuid      = Guid.Empty;
                newChat.LastEditUserGuid = Guid.Empty;
                newChat.LastEditDate     = DateTime.Now;

                //foreach (var talker in newConversation.Persons)
                //{
                //    if(talker.PersonGuid==Guid.Empty)
                //        talker.PersonGuid=Guid.NewGuid();
                //    db.Set<Person>().Add(talker);
                //}

                foreach (var talk in newChat.Messages.Where(talk => talk.MessageGuid == Guid.Empty))
                {
                    talk.MessageGuid = Guid.NewGuid();
                }
                db.Set <Chat>().Add(newChat);
                return(db.SaveChanges() > 0);
            }
        }
Пример #10
0
 /// <summary>
 /// Supprimer definitivement un document
 /// </summary>
 /// <returns></returns>
 //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffDelete)]
 public bool DeleteDocument(Guid documentGuid)
 {
     using (var db = new StationContext()) {
         db.Set <Document>().Remove(db.Set <Document>().Find(documentGuid));
         return(db.SaveChanges() > 0);
     }
 }
Пример #11
0
        public bool Put(Pompe myPompe)
        {
            using (var db = new StationContext())
            {
                myPompe.LastEditDate = DateTime.Now;

                db.Pompes.Attach(myPompe);
                db.Entry(myPompe).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Пример #12
0
        public bool Put(Oil myOil)
        {
            using (var db = new StationContext())
            {
                myOil.LastEditDate = DateTime.Now;

                db.Oils.Attach(myOil);
                db.Entry(myOil).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Пример #13
0
        public bool Put(FuelPrelevement myPrelevement)
        {
            using (var db = new StationContext())
            {
                myPrelevement.LastEditDate = DateTime.Now;

                db.Set <FuelPrelevement>().Attach(myPrelevement);
                db.Entry(myPrelevement).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Пример #14
0
        public ActionResult Create([Bind(Include = "Id,MType")] MachineType machineType)
        {
            if (ModelState.IsValid)
            {
                var mt = db.MachineTypes.Where(x => x.MType == machineType.MType).Count();
                if (mt > 0)
                {
                    ViewBag.ErrorMessage = "Machine Type Already Exists";
                    return(View(machineType));
                }
                else
                {
                    db.MachineTypes.Add(machineType);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(machineType));
        }
Пример #15
0
 /// <summary>
 /// Supprimer un chat
 /// </summary>
 /// <param name="chatGuid"></param>
 /// <returns></returns>
 public bool DeleteChat(Guid chatGuid)
 {
     using (var db = new StationContext()) {
         var oldConversation = db.Set <Chat>().Find(chatGuid);
         oldConversation.IsDeleted      = true;
         oldConversation.DeleteUserGuid = Guid.Empty;
         db.Set <Chat>().Attach(oldConversation);
         db.Entry(oldConversation).State = EntityState.Modified;
         return(db.SaveChanges() > 0);
     }
 }
Пример #16
0
        /// <summary>
        /// Represente un enseignant, proff, staff, qui a la possibilite de se connecter a l'Eschool
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = Clearances.StaffWrite)]
        public bool SaveDocument(Document document)
        {
            using (var db = new StationContext()) {
                if (document.DocumentGuid == Guid.Empty)
                {
                    document.DocumentGuid = Guid.NewGuid();
                }

                db.Set <Document>().Add(document);
                return(db.SaveChanges() > 0);
            }
        }
Пример #17
0
        /// <summary>
        /// Modifier les information d'un salaire
        /// </summary>
        /// <param name="salary"></param>
        /// <exception cref="NotImplementedException"></exception>
        public bool CancelSalary(Salary salary)
        {
            if (string.IsNullOrEmpty(salary.Designation))
            {
                throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY");
            }
            if (salary.StartDate > salary.EndDate)
            {
                throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            }
            if (salary.EndDate < DateTime.Today)
            {
                throw new InvalidOperationException("END_DATE_CAN_NOT_BE_LESS_THAN_TODAY");
            }

            Employment emp;

            using (var db = new StationContext()) emp = db.Employments.Find(salary.EmploymentGuid);
            if (emp == null)
            {
                throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");
            }
            if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate))
            {
                throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES");
            }

            using (var db = new StationContext())
            {
                var newSalary = db.Salaries.Find(salary.SalaryGuid);
                if (newSalary == null)
                {
                    throw new InvalidOperationException("SALARY_REFERENCE_NOT_FOUND");
                }

                newSalary.EndDate     = salary.EndDate;
                newSalary.Description = salary.Description;

                var user = Membership.GetUser();
                if (user == null)
                {
                    throw new SecurityException("USER_CAN_NOT_DETERMINED");
                }

                // ReSharper disable once PossibleNullReferenceException
                newSalary.LastEditUserGuid = (Guid)user.ProviderUserKey;
                newSalary.LastEditDate     = DateTime.Now;

                db.Salaries.Attach(newSalary);
                db.Entry(newSalary).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Пример #18
0
 /// <summary>
 /// Supprimer un Message
 /// </summary>
 /// <param name="messageGuid"></param>
 /// <returns></returns>
 public bool DeleteMessage(Guid messageGuid)
 {
     using (var db = new StationContext())
     {
         var oldMessage = db.Conversations.Find(messageGuid);
         oldMessage.IsDeleted      = true;
         oldMessage.DeleteUserGuid = Guid.Empty;
         db.Conversations.Attach(oldMessage);
         db.Entry(oldMessage).State = EntityState.Modified;
         return(db.SaveChanges() > 0);
     }
 }
Пример #19
0
        public bool UpdateStaff(Staff mStaff)
        {
            using (var db = new StationContext())
            {
                db.Staffs.Attach(mStaff);
                db.Entry(mStaff).State = EntityState.Modified;

                db.Set <Person>().Attach(mStaff.Person);
                db.Entry(mStaff.Person).State = EntityState.Modified;

                return(db.SaveChanges() > 0);
            }
        }
Пример #20
0
 public StationController(StationContext context)
 {
     this.db = context;
     if (!db.Station.Any())
     {
         db.Station.Add(new GasStation {
             Adress = "Some St.", NameGas = "A95", Name = "WOG", Liters = 26, ValuesGas = 2
         });
         db.Station.Add(new GasStation {
             Adress = "Some St.", NameGas = "A98", Name = "PLG", Liters = 35, ValuesGas = 5
         });
         db.SaveChanges();
     }
 }
Пример #21
0
        /// <summary>
        /// Envoyer Un Chat
        /// </summary>
        /// <param name="newMessage"></param>
        /// <returns></returns>
        public bool PushChat(Message newMessage)
        {
            using (var db = new StationContext()) {
                if (db.Set <Person>().Find(newMessage.SenderGuid) == null)
                {
                    throw new InvalidOperationException("SENDER_REFERENCE_NOT_FOUND");
                }
                if (newMessage.MessageGuid == Guid.Empty)
                {
                    newMessage.MessageGuid = Guid.NewGuid();
                }
                if (db.Set <Chat>().Find(newMessage.ChatGuid) == null)
                {
                    throw new InvalidOperationException("CONVERSATION_REFERENCE_NOT_FOUND");
                }

                newMessage.DateAdded        = DateTime.Now;
                newMessage.AddUserGuid      = Guid.Empty;
                newMessage.LastEditUserGuid = Guid.Empty;
                newMessage.LastEditDate     = DateTime.Now;

                if (newMessage.Attachement == null)
                {
                    return(db.SaveChanges() > 0);
                }

                if (newMessage.Attachement.DocumentGuid == Guid.Empty)
                {
                    newMessage.Attachement.DocumentGuid = Guid.NewGuid();
                }
                db.Set <Document>().Add(newMessage.Attachement);
                db.Set <Message>().Add(newMessage);

                return(db.SaveChanges() > 0);
            }
        }
Пример #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="salary"></param>
        /// <returns></returns>
        protected internal static bool StaticAddSalary(Salary salary)
        {
            if (SalaryExist(salary))
            {
                return(true);
            }
            if (string.IsNullOrEmpty(salary.Designation))
            {
                throw new InvalidOperationException("DESIGNATION_CAN_NOT_BE_EMPTY");
            }
            if (salary.StartDate > salary.EndDate)
            {
                throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            }

            Employment emp;

            using (var db = new StationContext()) emp = db.Employments.Find(salary.EmploymentGuid);

            if (emp == null)
            {
                throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");
            }
            if ((salary.StartDate < emp.StartDate) || (salary.EndDate > emp.EndDate))
            {
                throw new InvalidOperationException("DATES_CAN_NOT_BE_OUT_OF_EMPLOYMENT_BOUNDRIES");
            }

            using (var db = new StationContext())
            {
                if (salary.SalaryGuid == Guid.Empty)
                {
                    salary.SalaryGuid = Guid.NewGuid();
                }
                if (salary.Description == string.Empty)
                {
                    salary.Description = salary.Designation;
                }

                salary.DateAdded        = DateTime.Now;
                salary.AddUserGuid      = Guid.Empty;
                salary.LastEditDate     = DateTime.Now;
                salary.LastEditUserGuid = Guid.Empty;

                db.Salaries.Add(salary);
                return(db.SaveChanges() > 0);
            }
        }
Пример #23
0
        public bool Post(Oil myOil)
        {
            using (var db = new StationContext())
            {
                if (myOil.OilGuid == Guid.Empty)
                {
                    myOil.OilGuid = Guid.NewGuid();
                }

                myOil.DateAdded    = DateTime.Now;
                myOil.LastEditDate = DateTime.Now;

                db.Oils.Add(myOil);
                return(db.SaveChanges() > 0);
            }
        }
Пример #24
0
        public bool Post(OilDelivery myDelivery)
        {
            using (var db = new StationContext())
            {
                if (myDelivery.OilDeliveryGuid == Guid.Empty)
                {
                    myDelivery.OilDeliveryGuid = Guid.NewGuid();
                }

                myDelivery.DateAdded    = DateTime.Now;
                myDelivery.LastEditDate = DateTime.Now;

                db.OilDeliveries.Add(myDelivery);
                return(db.SaveChanges() > 0);
            }
        }
Пример #25
0
        /// <summary>
        /// Modifier les information d'un employement
        /// </summary>
        /// <param name="employ"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public bool UpdateEmployment(Employment employ)
        {
            if (string.IsNullOrEmpty(employ.Position))
            {
                throw new InvalidOperationException("POSITION_CAN_NOT_BE_EMPTY");
            }
            if (employ.StartDate > employ.EndDate)
            {
                throw new InvalidOperationException("START_DATE_SUPERIOR_TO_END_DATE");
            }
            using (var db = new StationContext()) if (db.Staffs.Find(employ.StaffGuid) == null)
                {
                    throw new InvalidOperationException("STAFF_REFERENCE_NOT_FOUND");
                }

            using (var db = new StationContext())
            {
                var newEmploy = db.Employments.Find(employ.EmploymentGuid);
                if (newEmploy == null)
                {
                    throw new InvalidOperationException("EMPLOYEMENT_REFERENCE_NOT_FOUND");
                }

                //todo cancel Employ
                newEmploy.Position    = employ.Position;
                newEmploy.Category    = employ.Category;
                newEmploy.Project     = employ.Project;
                newEmploy.Grade       = employ.Grade;
                newEmploy.Departement = employ.Departement;
                newEmploy.Division    = employ.Division;
                newEmploy.ReportTo    = employ.ReportTo;
                //newEmploy.SalaryRecurrence = employ.SalaryRecurrence;
                //newEmploy.StartDate        = employ.StartDate;
                //newEmploy.EndDate          = employ.EndDate;
                newEmploy.Description = employ.Description;

                newEmploy.LastEditDate     = DateTime.Now;
                newEmploy.LastEditUserGuid = Guid.Empty;

                db.Employments.Attach(newEmploy);
                db.Entry(newEmploy).State = EntityState.Modified;

                return(db.SaveChanges() > 0);
            }
        }
Пример #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="messageGuid"></param>
        /// <param name="markRead"></param>
        /// <returns></returns>
        public Conversation GetMessage(Guid messageGuid, bool markRead = true)
        {
            using (var db = new StationContext())
            {
                var oldMessage = db.Conversations.Find(messageGuid);
                if (oldMessage == null)
                {
                    return(null);
                }

                oldMessage.IsRead       = true;
                oldMessage.LastEditDate = DateTime.Now;
                db.Conversations.Attach(oldMessage);
                db.Entry(oldMessage).State = EntityState.Modified;
                db.SaveChanges();
                return(oldMessage);
            }
        }
Пример #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="customerGuid"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.StaffDelete)]
        public bool Delete(Guid customerGuid)
        {
            using (var db = new StationContext())
            {
                var theMan = db.Customers.Find(customerGuid);

                Guard.WhenArgument(theMan, "CAN_NOT_FIND_STAFF_REFERENCE").IsNull().Throw();

                theMan.Person.DeleteDate = DateTime.Now;
                theMan.Person.IsDeleted  = true;
                // ReSharper disable once PossibleNullReferenceException
                theMan.Person.DeleteUserGuid = (Guid)Membership.GetUser().ProviderUserKey;

                db.Customers.Attach(theMan);
                db.Entry(theMan).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Пример #28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="myCustomer"></param>
        /// <returns></returns>
        //[PrincipalPermission(SecurityAction.Demand, Role = SecurityClearances.StaffWrite)]
        public bool UpdateCustomer(Customer myCustomer)
        {
            using (var db = new StationContext())
            {
                // ReSharper disable once PossibleNullReferenceException
                var userTrace = (Guid)Membership.GetUser().ProviderUserKey;
                myCustomer.LastEditDate     = DateTime.Now;
                myCustomer.LastEditUserGuid = userTrace;

                db.Customers.Attach(myCustomer);
                db.Entry(myCustomer).State = EntityState.Modified;

                db.Set <Person>().Attach(myCustomer.Person);
                db.Entry(myCustomer.Person).State = EntityState.Modified;

                return(db.SaveChanges() > 0);
            }
        }
Пример #29
0
        /// <summary>
        /// Confirmer paiement d'un salaire
        /// </summary>
        /// <param name="payrollGuid"></param>
        /// <param name="finalPaycheck"></param>
        /// <param name="numeroReference"></param>
        /// <param name="totalHoursWorked"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public bool Paycheck(Guid payrollGuid, double?finalPaycheck = null, string numeroReference = null, TimeSpan?totalHoursWorked = null)
        {
            using (var db = new StationContext()) {
                var payroll = db.Payrolls.Find(payrollGuid);
                if (payroll == null)
                {
                    throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND");
                }

                if (payroll.IsPaid)
                {
                    throw new InvalidOperationException("PAYCHECK_ALREADY_PAID");
                }

                if (!string.IsNullOrEmpty(numeroReference) && SalarySlipExist(numeroReference))
                {
                    throw new InvalidOperationException("PAYSLIP_REFERENCE_DUPLICATE");
                }

                if (totalHoursWorked != null)
                {
                    payroll.HoursWorked = (TimeSpan)totalHoursWorked;
                }

                if (finalPaycheck == null)
                {
                    finalPaycheck = (new PayrollCard(payroll)).TotalSalary;
                }

                payroll.FinalPaycheck   = (double)finalPaycheck;
                payroll.IsPaid          = true;
                payroll.IsPaidTo        = Guid.Empty;
                payroll.DatePaid        = DateTime.Now;
                payroll.NumeroReference = string.IsNullOrEmpty(numeroReference) ? GetNewSalarySlipRef() : numeroReference;

                payroll.LastEditDate     = DateTime.Now;
                payroll.LastEditUserGuid = Guid.Empty;

                db.Payrolls.Attach(payroll);
                db.Entry(payroll).State = EntityState.Modified;

                return(db.SaveChanges() > 0);
            }
        }
Пример #30
0
        public bool DeleteStaff(Guid staffGuid)
        {
            using (var db = new StationContext())
            {
                var theMan = db.Staffs.Find(staffGuid);

                if (theMan == null)
                {
                    throw new InvalidOperationException("CAN_NOT_FIND_STAFF_REFERENCE");
                }

                theMan.Person.DeleteDate     = DateTime.Now;
                theMan.Person.IsDeleted      = true;
                theMan.Person.DeleteUserGuid = Guid.Empty;

                db.Staffs.Attach(theMan);
                db.Entry(theMan).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }