Esempio n. 1
0
        public long CreateFuel(FuelData fuelData, UserOpMap userOpMap)
        {
            DAL_Fuel      dAL_Fuel      = new DAL_Fuel();
            Fuel          fuel          = new Fuel();
            DailyFuelCost dailyFuelCost = new DailyFuelCost();

            fuel.Name                  = fuelData.Name;
            fuel.Description           = fuelData.Description;
            fuel.Type                  = fuelData.Type;
            dailyFuelCost.CostPerLiter = fuelData.CostPerLiter;
            return(dAL_Fuel.CreateFuel(fuel, dailyFuelCost, userOpMap));
        }
Esempio n. 2
0
        public long UpdateFuel(Fuel fuel, DailyFuelCost dailyFuelCost, UserOpMap userOpMap)
        {
            using (var dbContext = new ppmsEntities())
            {
                Fuel fuelData = new Fuel();
                fuelData = (from a in dbContext.Fuels
                            where a.IsActive == true && a.Id == fuel.Id
                            select a).FirstOrDefault();
                fuelData.Description = fuel.Description;
                fuelData.Type        = fuel.Type;
                dbContext.SaveChanges();

                dailyFuelCost.CreatedBy = Convert.ToInt64(userOpMap.UserID);
                dailyFuelCost.Updatedby = Convert.ToInt64(userOpMap.UserID);
                dailyFuelCost.UpdatedOn = DateTime.Now;
                dailyFuelCost.CreatedOn = DateTime.Now;
                dailyFuelCost.IsActive  = true;

                dbContext.DailyFuelCosts.Add(dailyFuelCost);
                dbContext.SaveChanges();//this generates the Id for customer
                return(dailyFuelCost.Id);
            }
        }
Esempio n. 3
0
        public long CreateFuel(Fuel fuel, DailyFuelCost dailyFuelCost, UserOpMap userOpMap)
        {
            using (var dbContext = new ppmsEntities())
            {
                Fuel fuelData = new Fuel();
                fuelData = (from a in dbContext.Fuels
                            where a.IsActive == true && a.Name == fuel.Name && a.Type == fuel.Type
                            select a).FirstOrDefault();
                if (fuelData == null)
                {
                    //Create Fuel
                    fuel.IsActive  = true;
                    fuel.CreatedBy = Convert.ToInt64(userOpMap.UserID);
                    fuel.Updatedby = Convert.ToInt64(userOpMap.UserID);
                    fuel.CreatedOn = DateTime.Now;
                    fuel.UpdatedOn = DateTime.Now;
                    dbContext.Fuels.Add(fuel);
                    dbContext.SaveChanges();
                    int fuelID = fuel.Id;

                    dailyFuelCost.CreatedBy  = Convert.ToInt64(userOpMap.UserID);
                    dailyFuelCost.Updatedby  = Convert.ToInt64(userOpMap.UserID);
                    dailyFuelCost.UpdatedOn  = DateTime.Now;
                    dailyFuelCost.CreatedOn  = DateTime.Now;
                    dailyFuelCost.IsActive   = true;
                    dailyFuelCost.FuelTypeId = fuelID;

                    dbContext.DailyFuelCosts.Add(dailyFuelCost);
                    dbContext.SaveChanges();//this generates the Id for customer
                    return(dailyFuelCost.Id);
                }
                else
                {
                    throw new Exception("Fuel already exist !");
                }
            }
        }