示例#1
0
        public ActionResult Edit(int id, tbl_Cage tbl_Cage)
        {
            string actionName = "Edit";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                if (ModelState.IsValid)
                {
                    if (id <= 0)
                    {
                        Alert("Invalid Cage Selected.", NotificationType.error);
                        _logger.Log(LogLevel.Trace, actionName + " :: Ended. Invalid cage id : " + id);
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }

                    using (var db = new WebAppDbContext())
                    {
                        var cage = db.tbl_Cage.FirstOrDefault(x => x.CageId == id);
                        if (cage != null && (cage?.CageCode == tbl_Cage.CageCode))
                        {
                            cage.CageName   = tbl_Cage.CageName;
                            cage.Address    = tbl_Cage.Address;
                            cage.Country    = tbl_Cage.Country;
                            cage.City       = tbl_Cage.City;
                            cage.PostalCode = tbl_Cage.PostalCode;
                            cage.Status     = tbl_Cage.Status;

                            cage.ModifiedByUser = Session[SessionKeys.UserId]?.ToString();
                            cage.ModifiedOnDate = DateTime.Now;

                            db.Entry(cage).State = EntityState.Modified;
                            db.SaveChanges();

                            Alert("Record Updated Successfully.", NotificationType.success);
                        }
                        else
                        {
                            Alert("Cage Not Found.", NotificationType.error);
                            _logger.Log(LogLevel.Trace, actionName + " :: Ended. Cage not found for cage id : " + id);
                        }
                    }
                }
                else
                {
                    _logger.Log(LogLevel.Trace, actionName + " :: Ended. Model state is not valid for cage id : " + id);
                    CageViewModels objCageViewModels = GetCage(id);
                    return(PartialView("_Edit", objCageViewModels));
                }
            }
            catch (Exception ex)
            {
                Alert("Something Went Wrong !!!", NotificationType.error);
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
                Exception(ex);
            }

            return(RedirectToAction("Index"));
        }
示例#2
0
        public ActionResult Edit(int id)
        {
            string actionName = "Edit";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");
            CageViewModels objCageViewModels = new CageViewModels();

            try
            {
                if (id <= 0)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                objCageViewModels = GetCage(id);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(PartialView("_Edit", objCageViewModels));
        }
示例#3
0
        public ActionResult Create(tbl_Cage tbl_Cage)
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");

            try
            {
                if (ModelState.IsValid)
                {
                    using (var db = new WebAppDbContext())
                    {
                        if (!db.tbl_Cage.Any(x => x.CageCode == tbl_Cage.CageCode))
                        {
                            // Get Current user Id
                            var userId = Session[SessionKeys.UserId]?.ToString();
                            tbl_Cage.CreatedByUser  = userId;
                            tbl_Cage.ModifiedByUser = userId;

                            //Get Current Date & Time.
                            tbl_Cage.CreatedOnDate  = DateTime.Now;
                            tbl_Cage.ModifiedOnDate = DateTime.Now;
                            tbl_Cage.Status         = "Active";

                            db.tbl_Cage.Add(tbl_Cage);
                            db.SaveChanges();


                            Alert("Record Added Successfully !! ", NotificationType.success);
                        }
                        else
                        {
                            _logger.Log(LogLevel.Trace, actionName + " :: Cage code : " + tbl_Cage.CageCode + " already exist.");
                            Alert("Cage code already exist.", NotificationType.error);
                        }
                    }
                }
                else
                {
                    CageViewModels vm = new CageViewModels();

                    SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                    vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);

                    _logger.Log(LogLevel.Trace, actionName + " :: Model state not valid.");
                    return(PartialView("_Create", vm));
                }
            }
            catch (Exception ex)
            {
                Alert("Their is something went wrong!!!", NotificationType.error);
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
                Exception(ex);
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(RedirectToAction("Index"));
        }
示例#4
0
 private CageViewModels GetCage(int id)
 {
     SessionKeys.LoadTablesInSession(SessionKeys.Countries);
     using (var db = new WebAppDbContext())
     {
         var viewModel = new CageViewModels()
         {
             tbl_Cage     = db.tbl_Cage.FirstOrDefault(x => x.CageId == id),
             _tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]),
         };
         return(viewModel);
     }
 }
示例#5
0
        public ActionResult Create()
        {
            string actionName = "Create";

            _logger.Log(LogLevel.Trace, actionName + " :: started.");
            CageViewModels vm = new CageViewModels();

            try
            {
                SessionKeys.LoadTablesInSession(SessionKeys.Countries, "", "");
                vm._tbl_Country = ((List <ClassLibrary.Models.tbl_Country>)Session[SessionKeys.Countries]);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");
            return(PartialView("_Create", vm));
        }
示例#6
0
        public ActionResult Index()
        {
            string actionName = "Index";

            _logger.Log(LogLevel.Error, actionName + " :: started.");

            CageViewModels cageVM = new CageViewModels();

            try
            {
                using (var db = new WebAppDbContext())
                {
                    List <GraphData> data = new List <GraphData>();

                    var cages     = db.tbl_Cage.ToList();
                    var countries = cages?.Select(x => x.Country).Distinct();

                    cageVM.cageCount        = cages?.Count();
                    cageVM.cageActiveCount  = cages.Where(x => x.Status == "Active")?.Count();
                    cageVM.CageCountryCount = countries?.Count();

                    foreach (var item in countries)
                    {
                        GraphData details = new GraphData();
                        details.label = item;
                        details.value = cages.Where(x => x.Country == item && x.Status == "Active")?.Count();
                        data.Add(details);
                    }

                    cageVM.dataList = data;
                }
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString());
            }

            _logger.Log(LogLevel.Trace, actionName + " :: ended.");

            return(View(cageVM));
        }