Ejemplo n.º 1
0
        public int Created(ModifireModel data)
        {
            try
            {

                if (data.ModifireID == 0)
                {
                    var checkdata = _context.MODIFIREs.Where(x => x.ModifireName == data.ModifireName).ToList();
                    if (checkdata.Count() > 0)
                    {
                        return -1;
                    }

                    var new_data = new MODIFIRE();
                    new_data.ModifireName = data.ModifireName;
                    new_data.Color = data.Color ?? "";
                    new_data.Status = 1;
                    new_data.CreateBy = data.CreateBy ?? 0;
                    new_data.CreateDate = DateTime.Now;
                    new_data.UpdateBy = data.UpdateBy ?? 0;
                    new_data.UpdateDate = DateTime.Now;
                    new_data.Note = data.Note ?? "";

                    _context.Entry(new_data).State = EntityState.Added;
                    _context.SaveChanges();
                    var modifire_price = new MODIFIRE_PRICE();
                    modifire_price.ModifireID = new_data.ModifireID;
                    modifire_price.CurrentPrice = data.CurrentPrice;
                    modifire_price.CreateBy = data.CreateBy ?? 0;
                    modifire_price.CreateDate = DateTime.Now;
                    modifire_price.UpdateBy = data.UpdateBy ?? 0;
                    modifire_price.UpdateDate = DateTime.Now;
                    modifire_price.Note = data.Note ?? "";
                    var result = CreatedModifirePrice(modifire_price);
                    return result;

                }
                else
                {
                    var checkdata = _context.MODIFIREs.Where(x => x.ModifireName == data.ModifireName && x.ModifireID != data.ModifireID).ToList();
                    if (checkdata.Count() > 0)
                    {
                        return -1;
                    }
                    var old_data = _context.MODIFIREs.Find(data.ModifireID);
                    if (old_data != null)
                    {
                        old_data.ModifireName = data.ModifireName;
                        old_data.Color = data.Color ?? "";
                        old_data.Status = 1;
                        old_data.UpdateBy = data.UpdateBy ?? 0;
                        old_data.UpdateDate = DateTime.Now;
                        old_data.Note = data.Note ?? "";

                        _context.Entry(old_data).State = EntityState.Modified;
                        _context.SaveChanges();
                        var modifire_price = new MODIFIRE_PRICE();
                        modifire_price.ModifireID = data.ModifireID;
                        modifire_price.CurrentPrice = data.CurrentPrice;
                        modifire_price.CreateBy = data.CreateBy ?? 0;
                        modifire_price.CreateDate = DateTime.Now;
                        modifire_price.UpdateBy = data.UpdateBy ?? 0;
                        modifire_price.UpdateDate = DateTime.Now;
                        modifire_price.Note = data.Note ?? "";
                        var result = CreatedModifirePrice(modifire_price);
                        return result;
                    }
                    return 0;

                }
            }
            catch (Exception)
            {
                return 0;
            }
        }
Ejemplo n.º 2
0
 public int CreatedModifirePrice(MODIFIRE_PRICE modifire_price)
 {
     try
     {
         var data = _context.MODIFIRE_PRICE.Where(x => x.ModifireID == modifire_price.ModifireID).SingleOrDefault();
         if (data != null)
         {
             data.WasPrice = data.CurrentPrice;
             data.CurrentPrice = modifire_price.CurrentPrice;
             data.Status = 1;
             data.UpdateBy = modifire_price.UpdateBy;
             data.UpdateDate = modifire_price.UpdateDate;
             data.CreateBy = modifire_price.CreateBy;
             data.CreateDate = modifire_price.CreateDate;
             data.Note = modifire_price.Note;
             _context.Entry(data).State = EntityState.Modified;
             _context.SaveChanges();
             return 1;
         }
         else
         {
             var new_data = new MODIFIRE_PRICE();
             new_data.ModifireID = modifire_price.ModifireID;
             new_data.WasPrice = 0;
             new_data.CurrentPrice = modifire_price.CurrentPrice;
             new_data.Status = 1;
             new_data.UpdateBy = modifire_price.UpdateBy;
             new_data.UpdateDate = modifire_price.UpdateDate;
             new_data.CreateBy = modifire_price.CreateBy;
             new_data.CreateDate = modifire_price.CreateDate;
             new_data.Note = modifire_price.Note;
             _context.Entry(new_data).State = EntityState.Added;
             _context.SaveChanges();
             return 1;
         }
     }
     catch (Exception)
     {
         return 0;
     }
 }