Пример #1
0
        /// <summary>
        /// to delete location x location group by id
        /// </summary>
        public bool DeleteLocByLocGroupByIDs(int LocationID, int LocationGroupID)
        {
            using (Entities db = new Entities())
            {
                bool isDeleted = false;

                REF_LOCATION_X_LOCATION_GROUP_TB result = db.REF_LOCATION_X_LOCATION_GROUP_TB
                                                          .FirstOrDefault(u => u.N_LOCATION_SYSID == LocationID && u.N_LOCATION_GROUP_SYSID == LocationGroupID);

                db.REF_LOCATION_X_LOCATION_GROUP_TB.Remove(result);
                db.SaveChanges();
                isDeleted = true;

                return(isDeleted);
            }
        }
        public ActionResult Create(LocationGroupCreateLocationViewModel Model, bool IsTest = false)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    REF_LOCATION_X_LOCATION_GROUP_TB record = new REF_LOCATION_X_LOCATION_GROUP_TB()
                    {
                        B_INACTIVE             = false,
                        DT_ENTERED             = DateTime.UtcNow,
                        DT_MODIFIED            = DateTime.UtcNow,
                        N_LOCATION_GROUP_SYSID = Model.LocationGroupID,
                        N_LOCATION_SYSID       = Model.SelectedLocation,
                        SZ_ENTERED_BY          = IsTest ? "Unit Test Case" : _modifiedBy,
                        SZ_MODIFIED_BY         = _modifiedBy
                    };

                    _uow.Repository <REF_LOCATION_X_LOCATION_GROUP_TB>().Add(record);
                    _uow.SaveChanges();

                    return(RedirectToAction("Details", new { ID = Model.LocationGroupID }));
                }

                Model.Locations = (List <SelectListItem>)_locationRepo.GetLocationsSelectListByLocationGroupID(Model.LocationGroupID);

                return(View(Model));
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    ViewBag.Message = "Function: LocationGroupController.Create_POST\n\nError: " + ex.Message;
                }
                else
                {
                    ViewBag.Message = "Function: LocationGroupController.Craete_POST\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message);
                };
                Session["ErrorMessage"] = ViewBag.Message;
                return(RedirectToAction("InternalServerError", "Error"));
            };
        }