Esempio n. 1
0
        public ActionResult Edit(ContactViewModel contactVM) // Mater Relationship
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Save ContactRelationship").Add("Status", contactVM.Status)
                        .Add("RelationshipName", contactVM.RelationshipName).Add("RelationshipDesc", contactVM.RelationshipDesc).ToInputLogString());
            try
            {
                if (ModelState.IsValid)
                {
                    RelationshipEntity relationEntity = new RelationshipEntity
                    {
                        RelationshipId   = contactVM.RelationshipId.HasValue ? contactVM.RelationshipId.Value : 0,
                        Status           = contactVM.Status,
                        RelationshipName = contactVM.RelationshipName,
                        RelationshipDesc = contactVM.RelationshipDesc,
                        CreateUser       = UserInfo, //When save the progame will select to save this parameter
                        UpdateUser       = UserInfo
                    };

                    _customerFacade = new CustomerFacade();
                    // Check Duplicate
                    if (_customerFacade.IsDuplicateRelationship(relationEntity) == true)
                    {
                        ViewBag.ErrorMessage = Resource.Error_SaveFailedDuplicate;
                        goto Outer;
                    }

                    bool success = _customerFacade.SaveContactRelation(relationEntity);
                    if (success)
                    {
                        return(RedirectToAction("Search", "Contact"));
                    }
                    ViewBag.ErrorMessage = Resource.Error_SaveFailed;
                }

Outer:
                TempData["contactVM"] = contactVM;
                return(InitEdit());
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Save ContactRelationship").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }