public ActionResult Edit(WaterBodyEditViewModel Model)
        {
            if (_waterBodyRepo.IsWaterBodyNameAndDescriptionDuplicate(Model.WaterBodyName, Model.WaterBodyDescription))
            {
                Model.ShowMessageNameAndDescription = true;
                Model.MessageNameAndDescription     = "The Water Body Name and Description combination already exists. Please enter a different one.";

                return(View(Model));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    int id = 0;
                    if (Model.WaterBodyID == 0) //new
                    {
                        REF_WATER_BODY_TB waterBody = new REF_WATER_BODY_TB()
                        {
                            B_INACTIVE     = false,
                            DT_ENTERED     = DateTime.UtcNow,
                            DT_MODIFIED    = DateTime.UtcNow,
                            SZ_ENTERED_BY  = _modifiedBy,
                            SZ_MODIFIED_BY = _modifiedBy,
                            SZ_DESCRIPTION = Model.WaterBodyDescription,
                            SZ_NAME        = Model.WaterBodyName
                        };
                        _uow.Repository <REF_WATER_BODY_TB>().Add(waterBody);
                        _uow.SaveChanges();
                        REF_WATER_BODY_TB waterBodyFound = _uow.Repository <REF_WATER_BODY_TB>().Find(u => u.SZ_ENTERED_BY == _modifiedBy &&
                                                                                                      u.SZ_MODIFIED_BY == _modifiedBy && u.SZ_DESCRIPTION == Model.WaterBodyDescription &&
                                                                                                      u.SZ_NAME == Model.WaterBodyName).FirstOrDefault();
                        id = waterBodyFound.N_WATER_BODY_SYSID;
                    }
                    else //edit
                    {
                        REF_WATER_BODY_TB waterBody = _uow.Repository <REF_WATER_BODY_TB>().GetById(Model.WaterBodyID);
                        waterBody.DT_MODIFIED    = DateTime.UtcNow;
                        waterBody.SZ_DESCRIPTION = Model.WaterBodyDescription;
                        waterBody.SZ_MODIFIED_BY = _modifiedBy;
                        waterBody.SZ_NAME        = Model.WaterBodyName;

                        _uow.Repository <REF_WATER_BODY_TB>().Update(waterBody);
                        _uow.SaveChanges();
                        id = Model.WaterBodyID;
                    }

                    return(RedirectToAction("Index", new { ID = id }));
                }

                return(View(Model));
            }
        }
        public ViewResult Edit(int ID)
        {
            var waterBodyEditViewModel = new WaterBodyEditViewModel();

            if (ID > 0)
            {
                REF_WATER_BODY_TB waterBody = _uow.Repository <REF_WATER_BODY_TB>().GetById(ID);
                waterBodyEditViewModel.WaterBodyDescription          = waterBody.SZ_DESCRIPTION == null ? "" : waterBody.SZ_DESCRIPTION;
                waterBodyEditViewModel.WaterBodyID                   = waterBody.N_WATER_BODY_SYSID;
                waterBodyEditViewModel.WaterBodyName                 = waterBody.SZ_NAME == null ? "" : waterBody.SZ_NAME;
                waterBodyEditViewModel.ShowMessageNameAndDescription = false;
                waterBodyEditViewModel.MessageNameAndDescription     = "";
            }
            else
            {
                waterBodyEditViewModel.WaterBodyDescription          = "";
                waterBodyEditViewModel.WaterBodyID                   = ID;
                waterBodyEditViewModel.WaterBodyName                 = "";
                waterBodyEditViewModel.ShowMessageNameAndDescription = false;
                waterBodyEditViewModel.MessageNameAndDescription     = "";
            }

            return(View("Edit", waterBodyEditViewModel));
        }