public ActionResult Delete(string ID)
        {
            try
            {
                REF_WATER_BODY_TB        waterBody = _uow.Repository <REF_WATER_BODY_TB>().GetById(Convert.ToInt32(ID));
                WaterBodyDeleteViewModel waterBodyDeleteViewModel = new WaterBodyDeleteViewModel()
                {
                    WaterBodyID                   = waterBody.N_WATER_BODY_SYSID,
                    WaterBodyName                 = waterBody.SZ_NAME,
                    WaterBodyDescription          = waterBody.SZ_DESCRIPTION,
                    MessageNameAndDescription     = "",
                    ShowMessageNameAndDescription = false
                };

                return(View(waterBodyDeleteViewModel));
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    ViewBag.Message = "Function: WaterBodyController.Delete_GET\n\nError: " + ex.Message;
                }
                else
                {
                    ViewBag.Message = "Function: WaterBodyController.Delete_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message);
                };
                Session["ErrorMessage"] = ViewBag.Message;
                return(RedirectToAction("InternalServerError", "Error"));
            };
        }
Beispiel #2
0
        public ActionResult Delete(string ID)
        {
            try
            {
                REF_WATER_BODY_TB             recWater = _uow.Repository <REF_WATER_BODY_TB>().GetById(Convert.ToInt32(ID));
                ReceivingWaterDeleteViewModel recWaterDeleteViewModel = new ReceivingWaterDeleteViewModel()
                {
                    ReceivingWaterID          = recWater.N_WATER_BODY_SYSID,
                    ReceivingWaterDescription = recWater.SZ_DESCRIPTION,
                    MessageDescription        = "",
                    ShowMessageDescription    = false
                };

                return(View(recWaterDeleteViewModel));
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    ViewBag.Message = "Function: ReceivingWaterController.Delete_GET\n\nError: " + ex.Message;
                }
                else
                {
                    ViewBag.Message = "Function: ReceivingWaterController.Delete_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message);
                };
                Session["ErrorMessage"] = ViewBag.Message;
                return(RedirectToAction("InternalServerError", "Error"));
            };
        }
        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));
            }
        }
Beispiel #4
0
        public ActionResult Edit(int ID)
        {
            try
            {
                var receivingWaterEditViewModel = new ReceivingWaterEditViewModel();
                if (ID > 0)
                {
                    REF_WATER_BODY_TB receivingWater = _uow.Repository <REF_WATER_BODY_TB>().GetById(ID);
                    receivingWaterEditViewModel.ReceivingWaterDescription = receivingWater.SZ_DESCRIPTION == null ? "" : receivingWater.SZ_DESCRIPTION;
                    receivingWaterEditViewModel.ReceivingWaterID          = receivingWater.N_WATER_BODY_SYSID;
                    receivingWaterEditViewModel.ShowMessageDescription    = false;
                    receivingWaterEditViewModel.MessageDescription        = "";
                }
                else
                {
                    receivingWaterEditViewModel.ReceivingWaterDescription = "";
                    receivingWaterEditViewModel.ReceivingWaterID          = ID;
                    receivingWaterEditViewModel.ShowMessageDescription    = false;
                    receivingWaterEditViewModel.MessageDescription        = "";
                }

                return(View("Edit", receivingWaterEditViewModel));
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    ViewBag.Message = "Function: ReceivingWaterController.Edit_GET\n\nError: " + ex.Message;
                }
                else
                {
                    ViewBag.Message = "Function: ReceivingWaterController.Edit_GET\n\nError: " + (ex.Message + "\n\nInnerException: " + ex.InnerException.Message);
                };
                Session["ErrorMessage"] = ViewBag.Message;
                return(RedirectToAction("InternalServerError", "Error"));
            };
        }
        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));
        }
Beispiel #6
0
        public ActionResult Edit(ReceivingWaterEditViewModel Model)
        {
            bool saveFailed;

            do
            {
                saveFailed = false;
                try
                {
                    if (_receivingWaterRepo.IsReceivingWaterDescriptionDuplicate(Model.ReceivingWaterDescription))
                    {
                        Model.ShowMessageDescription = true;
                        Model.MessageDescription     = "The Receiving Water Description already exists. Please enter a different one.";

                        return(View(Model));
                    }
                    else
                    {
                        if (ModelState.IsValid)
                        {
                            int id = 0;
                            if (Model.ReceivingWaterID == 0) //new
                            {
                                int receivingWaterID             = _receivingWaterRepo.GetNextRecWaterID();
                                REF_WATER_BODY_TB receivingWater = new REF_WATER_BODY_TB()
                                {
                                    SZ_ENTERED_BY  = _modifiedBy,
                                    DT_ENTERED     = DateTime.UtcNow,
                                    SZ_MODIFIED_BY = _modifiedBy,
                                    DT_MODIFIED    = DateTime.UtcNow,
                                    SZ_NAME        = Model.ReceivingWaterDescription,
                                    SZ_DESCRIPTION = Model.ReceivingWaterDescription
                                };
                                _uow.Repository <REF_WATER_BODY_TB>().Add(receivingWater);
                                _uow.SaveChanges();
                                REF_WATER_BODY_TB receivingWaterFound = _uow.Repository <REF_WATER_BODY_TB>().Find(u => u.SZ_ENTERED_BY == _modifiedBy &&
                                                                                                                   u.SZ_MODIFIED_BY == _modifiedBy && u.SZ_DESCRIPTION == Model.ReceivingWaterDescription
                                                                                                                   ).FirstOrDefault();
                                id = receivingWaterFound.N_WATER_BODY_SYSID;
                            }
                            else //edit
                            {
                                REF_WATER_BODY_TB receivingWater = _uow.Repository <REF_WATER_BODY_TB>().GetById(Model.ReceivingWaterID);
                                receivingWater.SZ_MODIFIED_BY = _modifiedBy;
                                receivingWater.DT_MODIFIED    = DateTime.UtcNow;
                                receivingWater.SZ_DESCRIPTION = Model.ReceivingWaterDescription;

                                _uow.Repository <REF_WATER_BODY_TB>().Update(receivingWater);
                                _uow.SaveChanges();
                                id = Model.ReceivingWaterID;
                            }

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

                        return(View(Model));
                    }
                }
                catch (DbEntityValidationException ex)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var failure in ex.EntityValidationErrors)
                    {
                        sb.AppendFormat("{0} failed validation:\n\n", failure.Entry.Entity.GetType());
                        foreach (var error in failure.ValidationErrors)
                        {
                            sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage);
                            sb.AppendLine();
                        }
                    }
                    if (ex.InnerException == null)
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message + "\n\n" + sb;
                    }
                    else
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message + "\n\n" + sb + "\n\n" + ex.InnerException.Message;
                    };
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;

                    var entry = ex.Entries.Single();
                    entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                }
                catch (DataException ex)
                {
                    if (ex.InnerException == null)
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.GetBaseException().Message;
                    }
                    else
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.GetBaseException().Message + "\n\nInnerException: " + ex.InnerException.Message;
                    };
                }
                catch (Exception ex)
                {
                    if (ex.InnerException == null)
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message;
                    }
                    else
                    {
                        ViewBag.Message = "Function: ReceivingWaterController.Edit_POST\n\nError: " + ex.Message + "\n\nBaseException: " + ex.InnerException.Message;
                    };
                };
            } while (saveFailed);

            Session["ErrorMessage"] = ViewBag.Message;
            return(RedirectToAction("InternalServerError", "Error"));
        }