Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
 public ActionResult Edit([Bind(Include = "Id,RateDate,FuelType,RateValue")] Rate rate)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rate).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rate));
 }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,MType")] MachineType machineType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(machineType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(machineType));
 }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "Id,Company,Type,Quantity,DealingPerson,CNIC,PhoneNo,Address")] Stock stock)
 {
     if (ModelState.IsValid)
     {
         db.Entry(stock).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(stock));
 }
Ejemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "Id,CompanyName,ContactNo,Dealer,CNIC,Address")] Company company)
 {
     if (ModelState.IsValid)
     {
         db.Entry(company).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(company));
 }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> Put(Fuel myFuel)
        {
            using (var db = new StationContext())
            {
                myFuel.LastEditDate = DateTime.Now;

                db.Fuels.Attach(myFuel);
                db.Entry(myFuel).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
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);
     }
 }
Ejemplo n.º 12
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);
     }
 }
Ejemplo n.º 13
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);
            }
        }
Ejemplo n.º 14
0
        public async Task <bool> Put(Company myCompany)
        {
            bool result;

            using (var db = new StationContext())
            {
                myCompany.LastEditDate = DateTime.Now;

                db.Companies.Attach(myCompany);
                db.Entry(myCompany).State = EntityState.Modified;
                result = await db.SaveChangesAsync() > 0;
            }
            return(result);
        }
Ejemplo n.º 15
0
        public async Task <bool> ChangePrice(Guid oilGuid, double newPrice)
        {
            using (var db = new StationContext())
            {
                var myOil = db.Oils.Find(oilGuid);

                myOil.CurrentUnitPrice = newPrice;
                myOil.LastPriceUpdate  = DateTime.Now;

                myOil.LastEditDate = DateTime.Now;

                db.Oils.Attach(myOil);
                db.Entry(myOil).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 16
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);
            }
        }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
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);
            }
        }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
0
        public async Task <bool> DeletePurchase(Guid purchaseGuid)
        {
            using (var db = new StationContext())
            {
                var myPurchase = await db.Purchases.FindAsync(purchaseGuid);

                if (myPurchase == null)
                {
                    throw new InvalidOperationException("PURCHASE_NOT_FOUND");
                }

                myPurchase.LastEditDate = DateTime.Now;
                myPurchase.IsDeleted    = true;

                db.Purchases.Attach(myPurchase);
                db.Entry(myPurchase).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 21
0
        public ActionResult Edit([Bind(Include = "Id,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)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
Ejemplo n.º 22
0
        public async Task <bool> Delete(Guid fuelGuid)
        {
            using (var db = new StationContext())
            {
                var myObject = await db.Fuels.FindAsync(fuelGuid);

                if (myObject == null)
                {
                    throw new InvalidOperationException("FUEL_NOT_FOUND");
                }

                myObject.LastEditDate = DateTime.Now;
                myObject.IsDeleted    = true;

                db.Fuels.Attach(myObject);
                db.Entry(myObject).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 23
0
        public async Task <bool> DeletePrelevement(Guid oilPrelevementGuid)
        {
            using (var db = new StationContext())
            {
                var myObject = await db.OilPrelevements.FindAsync(oilPrelevementGuid);

                if (myObject == null)
                {
                    throw new InvalidOperationException("PRELEVEMENT_NOT_FOUND");
                }

                myObject.LastEditDate = DateTime.Now;
                myObject.DeleteDate   = DateTime.Now;
                myObject.IsDeleted    = true;

                db.OilPrelevements.Attach(myObject);
                db.Entry(myObject).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 24
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);
            }
        }
Ejemplo n.º 25
0
        public async Task <bool> CheckOut(Guid purchaseGuid, PurchaseState purchaseState = PurchaseState.Paid)
        {
            using (var db = new StationContext())
            {
                var myPurchase = await db.Purchases.FindAsync(purchaseGuid);

                if (myPurchase == null)
                {
                    throw new InvalidOperationException("ITEM_NOT_FOUND");
                }
                if (myPurchase.PurchaseState == purchaseState)
                {
                    throw new InvalidOperationException("ITEM_ALREADY_PAID");
                }

                myPurchase.PurchaseState = purchaseState;
                db.Purchases.Attach(myPurchase);
                db.Entry(myPurchase).State = EntityState.Modified;
                return(await db.SaveChangesAsync() > 0);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="transactionGuid"></param>
        /// <returns></returns>
        public bool CancelTransaction(Guid transactionGuid)
        {
            using (var db = new StationContext())
            {
                var theTransaction = db.Transactions.Find(transactionGuid);
                if (theTransaction == null)
                {
                    throw new InvalidOperationException("CAN_NOT_FIND_REFERENCE_TRANSACTION");
                }

                theTransaction.IsDeleted      = true;
                theTransaction.DeleteDate     = DateTime.Now;
                theTransaction.DeleteUserGuid = Guid.Empty;

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

                db.Transactions.Attach(theTransaction);
                db.Entry(theTransaction).State = EntityState.Modified;
                return(db.SaveChanges() > 0);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Annuler un Paiement d'un salaire
        /// </summary>
        /// <param name="payrollGuid"></param>
        public bool CancelPaycheck(Guid payrollGuid)
        {
            using (var db = new StationContext()) {
                var payroll = db.Payrolls.Find(payrollGuid);
                if (payroll == null)
                {
                    throw new InvalidOperationException("PAYROLL_REFERENCE_NOT_FOUND");
                }

                payroll.IsPaid          = false;
                payroll.IsPaidTo        = Guid.Empty;
                payroll.DatePaid        = DateTime.Now;
                payroll.NumeroReference = string.Empty;

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

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

                return(db.SaveChanges() > 0);
            }
        }
        public ActionResult Create([Bind(Include = "Type,MachineNumber,CurrentReading,CashRecieved")] DataEntry dataEntry)
        {
            if (ModelState.IsValid)
            {
                //Adding value to balance sheet
                var e     = db.DataEntries.Where(x => x.MachineNumber == dataEntry.MachineNumber).OrderByDescending(x => x.CreatedOn).FirstOrDefault();
                var sheet = new BalanceSheet();
                sheet.Cash      = dataEntry.CashRecieved;
                sheet.CreatedOn = DateTime.Now;
                if (e == null)
                {
                    sheet.FuelAmount = dataEntry.CurrentReading;
                }
                else
                {
                    sheet.FuelAmount = dataEntry.CurrentReading - e.CurrentReading;
                }

                sheet.FuelType = dataEntry.Type;
                sheet.Type     = "Sale";
                db.BalanceSheets.Add(sheet);
                db.SaveChanges();

                //Updating the stock tracker
                var a = sheet.FuelAmount;
                while (a != 0)
                {
                    var s = db.StockTrackers.Where(x => x.FuelType == dataEntry.Type && x.RemainingFuelAmount > 0).OrderBy(x => x.CreatedOn).FirstOrDefault();
                    s.UpdatedOn = DateTime.Now;
                    if (a < s.RemainingFuelAmount)
                    {
                        s.RemainingFuelAmount -= a;
                        a = 0;
                    }
                    else
                    {
                        a -= s.RemainingFuelAmount;
                        s.RemainingFuelAmount = 0;
                    }
                    db.Entry(s).State = EntityState.Modified;
                    db.SaveChanges();
                }



                //Creating dataentry
                dataEntry.CreatedBy = Session["LoggedIn"].ToString();
                dataEntry.CreatedOn = DateTime.Now;
                db.DataEntries.Add(dataEntry);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            List <SelectListItem> typeList = new List <SelectListItem>();
            var mt = db.MachineTypes.Distinct().ToList();

            foreach (var m in mt)
            {
                typeList.Add(new SelectListItem()
                {
                    Text = m.MType, Value = m.MType
                });
            }
            if (mt.Count > 0)
            {
                ViewBag.TypeList = new SelectList(typeList, "Value", "Text", typeList[0]);
            }
            else
            {
                ViewBag.TypeList = new SelectList(typeList, "Value", "Text");
            }

            var machines = new List <Machine>();

            if (mt.Count > 0)
            {
                machines = db.Machines.Where(x => x.Type == mt[0].MType).ToList();
            }
            else
            {
                machines = db.Machines.Distinct().ToList();
            }
            List <SelectListItem> mac = new List <SelectListItem>();

            foreach (var machine in machines)
            {
                mac.Add(new SelectListItem {
                    Text = machine.MachineNumber, Value = machine.MachineNumber
                });
            }
            if (machines.Count > 0)
            {
                ViewBag.MachineList = new SelectList(mac, "Value", "Text", machines[0]);
            }
            else
            {
                ViewBag.MachineList = new SelectList(mac, "Value", "Text");
            }


            return(View(dataEntry));
        }