Beispiel #1
0
        public ActionResult InitEdit(int?relationshipId = null)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("IntEdit ContactRelationship").Add("RelationshipId", relationshipId).ToInputLogString());

            try
            {
                ContactViewModel contactVM = null;

                if (TempData["contactVM"] != null)
                {
                    contactVM = (ContactViewModel)TempData["contactVM"];
                }
                else
                {
                    contactVM = new ContactViewModel {
                        RelationshipId = relationshipId
                    };
                }

                _commonFacade = new CommonFacade();
                var statusList = _commonFacade.GetStatusSelectList();
                contactVM.StatusList = new SelectList((IEnumerable)statusList, "Key", "Value", string.Empty);

                if (contactVM.RelationshipId != null)
                {
                    _customerFacade = new CustomerFacade();
                    RelationshipEntity relationshipEntity =
                        _customerFacade.GetRelationshipByID(contactVM.RelationshipId.Value);

                    contactVM.RelationshipId   = relationshipEntity.RelationshipId;
                    contactVM.RelationshipName = relationshipEntity.RelationshipName;
                    contactVM.RelationshipDesc = relationshipEntity.RelationshipDesc;
                    contactVM.Status           = relationshipEntity.Status;
                    contactVM.CreateUser       = relationshipEntity.CreateUserDisplay;
                    contactVM.UpdateUser       = relationshipEntity.UpdateUserDisplay;
                    contactVM.CreatedDate      =
                        relationshipEntity.CreatedDate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                    contactVM.UpdateDate =
                        relationshipEntity.Updatedate.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                }
                else
                {
                    // default UserLogin
                    if (this.UserInfo != null)
                    {
                        var today = DateTime.Now;
                        contactVM.CreateUser  = this.UserInfo.FullName;
                        contactVM.CreatedDate = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                        contactVM.UpdateDate  = today.FormatDateTime(Constants.DateTimeFormat.DefaultFullDateTime);
                        contactVM.UpdateUser  = this.UserInfo.FullName;
                    }
                }

                return(View("~/Views/Contact/Edit.cshtml", contactVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("IntEdit ContactRelationship").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }