Example #1
0
 internal static Staff VMStaffInformation_To_Staff(VM_StaffInformation vM_StaffInformation)
 {
     logger.EnterMethod();
     try
     {
         return(new Staff()
         {
             Id = vM_StaffInformation.Id,
             FirstName = vM_StaffInformation.FirstName,
             LastMiddle = vM_StaffInformation.LastMiddle,
             IdentifierNumber = vM_StaffInformation.IdentifierNumber,
             Image = vM_StaffInformation.Image,
             IsInUse = vM_StaffInformation.IsInUse,
             Salary = vM_StaffInformation.Salary,
             StaffCode = vM_StaffInformation.StaffCode,
             Summary = vM_StaffInformation.Summary
         });
     }
     catch (Exception e)
     {
         logger.Error("Error: [" + e.Message + "]");
         return(new Staff());
     }
     finally
     {
         logger.LeaveMethod();
     }
 }
        /// <summary>
        /// Go to CreateEmployee view
        ///     Generate employee code automatically
        /// </summary>
        /// <returns></returns>
        public ActionResult CreateEmployee()
        {
            logger.EnterMethod();
            var newEmp = new VM_StaffInformation();

            try
            {
                newEmp.StaffCode = this._iStaffServices.CreateNewCode();
                return(View(newEmp));
            }
            catch (Exception e)
            {
                logger.Error("Error: [" + e.Message + "]");
                return(View("ErrorAdminPage"));
            }
            finally
            {
                logger.LeaveMethod();
            }
        }
        public ActionResult SubmitUpdateEmployee(int id, string empCode, string empFirstName, string empLastMiddle, string empIdentifierNumber, string empAddress, string empDistrict, string empCity, string empCountry, string empPhone, string empEmail, string empWebsite, string empSummary)
        {
            logger.EnterMethod();
            try
            {
                var emp = new VM_StaffInformation()
                {
                    Id               = id,
                    StaffCode        = empCode,
                    FirstName        = empFirstName,
                    LastMiddle       = empLastMiddle,
                    IdentifierNumber = empIdentifierNumber,
                    Summary          = empSummary,
                    IsInUse          = true,
                    Image            = "[nullimage]",
                    Salary           = (decimal)0
                };
                var insertSuccess = this._iStaffServices.UpdateEmployee(ConvertVM.VMStaffInformation_To_Staff(emp));

                if (insertSuccess) // Insert new employee success
                {
                    var contactForId       = this._iContactInformationServices.GetContactForId("Staff");
                    var contactTypeId      = this._iContactInformationServices.GetContactTypeId("Address");
                    var empId              = this._iStaffServices.GetLast();
                    var contactInformation = new VM_ContactInformation()
                    {
                        Address = new VM_Address()
                        {
                            AddressNumberNoAndStreet = empAddress,
                            District = new VM_District()
                            {
                                DistrictName = empDistrict,
                                Province     = new VM_Province()
                                {
                                    ProvinceName = empCity,
                                    Country      = new VM_Country()
                                    {
                                        CountryName = empCountry
                                    }
                                }
                            }
                        },
                        ContactForId  = contactForId,
                        ContactTypeId = contactTypeId,
                        EAddress      = new VM_EAddress()
                        {
                            Email       = empEmail,
                            NumberPhone = empPhone,
                            Website     = empWebsite,
                            StaffId     = empId.Id
                        },
                        IsInUse  = true,
                        PersonId = empId.Id
                    };
                    var updateContactInformation = this._iContactInformationServices.CheckContactInformationExistingAndUpdateForPerson(ConvertVM.VMContactInformation_To_ContactInformation(contactInformation));
                    if (updateContactInformation)
                    {
                        return(Json(JsonConvert.SerializeObject(JObject.Parse(@"{insertEmp: true, updateContactInformation: true, personid: '" + empId.Id + "'}"))));
                    }
                    else
                    {
                        return(Json(JsonConvert.SerializeObject(JObject.Parse(@"{insertEmp: true, updateContactInformation: false, personid: '" + empId.Id + "'}"))));
                    }
                }
                else
                {
                    return(Json(JsonConvert.SerializeObject(JObject.Parse(@"{insertEmp: false}"))));
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error: [" + ex.Message + "]");
                return(Json(@"{insertEmp: false}"));
            }
            finally
            {
                logger.LeaveMethod();
            }
        }