public void Update(BatchView batchView, string userId)
        {
            using (var rep = new BatchRepository())
            {
                var   user  = _db.Users.ToList().Find(x => x.Id == userId);
                Batch batch = rep.GetById(batchView.BatchTypeid);
                if (batch != null)
                {
                    //batch.Batchid = batchView.Batchid;
                    batch.BatchTypeid = batchView.BatchTypeid;

                    batch.UserId = batchView.UserId;
                    // batch.Name = user.UserProfile.FirstName;
                    batch.BatchCode =
                        _TypeBl.GetBatchTypeById(batchView.BatchTypeid).BatchTypeDesc.Substring(0, 2) +
                        DateTime.Now;
                    batch.Agerange     = batchView.Agerange;
                    batch.NumOfAnimals = batchView.NumOfAnimals;
                    batch.Wiegth       = batchView.Wiegth;
                    batch.Totalcost    = batchView.Totalcost;
                }
                // rep.Update(batch);
                rep.Update(ConvertBatch(batchView, userId));
            }
        }
 public void Delete(BatchView batchView)
 {
     using (var rep = new BatchRepository())
     {
         //rep.Delete(ConvertBatch(batchView));
     }
 }
 public void Insert(BatchView batchView, String userId)
 {
     using (var rep = new BatchRepository())
     {
         rep.Insert(ConvertBatch(batchView, userId));
     }
 }
Beispiel #4
0
 public ActionResult EditBatch(BatchView model)
 {
     if (ModelState.IsValid)
     {
         ViewData["BatchType"] = _db.PopulateDropDownList();
         _db.Update(model, User.Identity.GetUserId());
         return(RedirectToAction("GetAllBatches"));
     }
     return(View(model));
 }
Beispiel #5
0
 public ActionResult Create(BatchView batchView)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             ViewData["BatchType"] = _db.PopulateDropDownList();
             return(View(batchView));
         }
         _db.Insert(batchView, User.Identity.GetUserId());
         return(RedirectToAction("InsertAnimals", "Animal"));
     }
     catch
     {
         ViewData["BatchType"] = _db.PopulateDropDownList(batchView.BatchTypeid);
         return(View(batchView));
     }
 }
        private static Batch ConvertBatch(BatchView batchView, String userId)
        {
            var bty  = new BatchTypeBl();
            var user = _db.Users.ToList().Find(x => x.Id == userId);

            var batch = new Batch
            {
                Batchid      = batchView.Batchid,
                BatchTypeid  = batchView.BatchTypeid,
                UserId       = batchView.UserId,
                Name         = user.UserProfile.FirstName,
                BatchCode    = bty.GetBatchTypeById(batchView.BatchTypeid).BatchTypeDesc.Substring(0, 2) + DateTime.Now,
                Agerange     = batchView.Agerange,
                NumOfAnimals = batchView.NumOfAnimals,
                Wiegth       = batchView.Wiegth,
                Totalcost    = batchView.Totalcost
            };

            return(batch);
        }