public ActionResult PerformBooking(int bedId, long customerId, long staffId, int yearfrom, int monthfrom, int dayfrom, int hoursfrom, int minutesfrom, int yearto, int monthto, int dayto, int hoursto, int minutesto, decimal cost, string services)
        {
            var vM_Book = new VM_Book()
            {
                BedId      = bedId,
                CustomerId = customerId,
                PeriodFrom = new DateTime(yearfrom, monthfrom, dayfrom, hoursfrom, minutesfrom, 0, 0),
                PeriodTo   = new DateTime(yearto, monthto, dayto, hoursto, minutesto, 0, 0),
                StaffId    = staffId,
                TotalCost  = cost
            };
            var check = this._iBookingServices.Booking(ConvertVM.VMBook_To_Bill(vM_Book));

            if (check)
            {
                // [SER-QVBG][SER-LEOC]
                List <string> codes = services.
                                      Replace("[]", ", ").
                                      Replace('[', ' ').
                                      Replace(']', ' ').
                                      Split(',').ToList();
                List <int> serviceIds = new List <int>();
                foreach (var code in codes)
                {
                    serviceIds.Add(this._iServiceServices.GetServiceIdByCode(code));
                }
                // Book detail
                //this._iBookingServices
            }
            return(Json(check));
        }
        public ActionResult Search(string key)
        {
            var       result    = this._iReferenceServices.Search(key);
            VM_Search vM_Search = ConvertVM.SearchResult_To_VMSearch(result);

            return(View(vM_Search));
        }
 public ActionResult BookNew(int bedId, string language = "en")
 {
     logger.EnterMethod();
     try
     {
         language = WebConfigurationManager.AppSettings[language];
         var newBooking = new VM_NewBooking();
         var services   = ConvertVM.Service_To_VMService(this._iServiceServices.GetAll());
         foreach (var item in services)
         {
             item.Name = this._iServiceServices.GetServiceNameByLanguage(item.Id, language);
         }
         newBooking.Services  = services;
         newBooking.Customers = ConvertVM.Customer_To_VMCustomer(this._iCustomerServices.GetAll().ToList());
         newBooking.BedId     = bedId;
         newBooking.BedName   = this._iBedServices.GetBedName(bedId, language);
         return(View(newBooking));
     }
     catch (Exception e)
     {
         logger.Error("Error: [" + e.Message + "]");
         return(View("ErrorAdminPage"));
     }
     finally
     {
         logger.LeaveMethod();
     }
 }
        /// <summary>
        /// Get all staff
        /// Convert to ListStaff in VM
        /// </summary>
        /// <param name="isInUse"></param>
        /// <returns></returns>
        public ActionResult Employees(int index = 1, bool inuse = true)
        {
            logger.EnterMethod();
            try
            {
                var allStaffes   = this._iStaffServices.GetStaffByPage(index, inuse);
                var vM_ListStaff = ConvertVM.ListStaff_To_VM_ListStaff(allStaffes.ToList());

                List <long> listStaffId = new List <long>();
                foreach (var item in allStaffes)
                {
                    listStaffId.Add(item.Id);
                }
                var listContactInformation = ConvertVM.ListContactInformation_To_ListVMContactInformation(
                    this._iContactInformationServices.GetContactInformationFromListStaff(listStaffId));
                var allPages = this._iStaffServices.CountTotalPages();
                return(View(ConvertVM.VM_ListStaff_Add_Paging(SelfConvertVM.VM_ListStaffAddContactInformation(listContactInformation, vM_ListStaff), index, allPages)));
            }
            catch (Exception e)
            {
                logger.Error("Error: [" + e.Message + "]");
                return(View("ErrorAdminPage"));
            }
            finally
            {
                logger.LeaveMethod();
            }
        }
        /// <summary>
        /// Get history paid salary for an employee
        /// </summary>
        /// <param name="empId"></param>
        /// <returns></returns>
        public ActionResult SalaryHistory(long empId)
        {
            logger.EnterMethod();
            try
            {
                var history = new VM_EmpSalaryPaying()
                {
                    ListEmpPaying = ConvertVM.Salary_To_VMSalaryPaying(this._iSalaryServices.GetSalariesForEmployee(empId))
                };
                foreach (var item in history.ListEmpPaying)
                {
                    item.SumDays = this._iSalaryServices.AttendanceInMonth(empId, item.Time);
                }
                var emp = this._iStaffServices.Get(empId);

                return(View(history));
            }
            catch (Exception e)
            {
                logger.Error("Error: [" + e.Message + "]");
                return(View("ErrorAdminPage"));
            }
            finally
            {
                logger.LeaveMethod();
            }
        }
        /// <summary>
        /// Get all bookings
        /// </summary>
        /// <returns></returns>
        public ActionResult Bookings(string lang = "en")
        {
            logger.EnterMethod();
            string language = WebConfigurationManager.AppSettings[lang];

            try
            {
                VM_ListBooking    vM_ListBooking = new VM_ListBooking();
                List <VM_Booking> vM_Bookings    = new List <VM_Booking>();
                List <VM_Bed>     vM_Beds        = ConvertVM.Bed_To_VMBed(this._iBedServices.GetAll());
                foreach (var item in vM_Beds)
                {
                    item.TimePeriod = ConvertVM.TimePeriod_To_VMTimePeriod(this._iBedServices.GetTimePeriodsForBed(item.Id));
                    item.Name       = this._iBedServices.GetBedName(item.Id, language);
                }
                vM_ListBooking.Bookings = ConvertVM.Bills_To_VMBookings(this._iBookingServices.GetAll());
                vM_ListBooking.Bookings = ConvertVM.Bills_To_VMBookings(this._iBookingServices.GetAll());
                vM_ListBooking.Beds     = vM_Beds;
                return(View(vM_ListBooking));
            }
            catch (Exception e)
            {
                logger.Error("Error: [" + e.Message + "]");
                return(View("ErrorAdminPage"));
            }
            finally
            {
                logger.LeaveMethod();
            }
        }
        public ActionResult CreateService()
        {
            VM_CreateService vM_CreateService = new VM_CreateService();

            vM_CreateService.ServiceCode = this._iServiceServices.CreateNewCode();
            var languges = this._iReferenceServices.GetAllLanguage();

            vM_CreateService.Languages = ConvertVM.Language_To_VMLanguage(languges);
            return(View(vM_CreateService));
        }
        public ActionResult Stocks(int index = 1)
        {
            VM_ListStock vM_ListStock = new VM_ListStock();
            var          listStock    = this._iStockServices.GetStockPaging(index);

            vM_ListStock = new VM_ListStock {
                Stocks = ConvertVM.Stock_To_VMStock(listStock)
            };
            return(View(vM_ListStock));
        }
        public ActionResult CreateBed()
        {
            VM_CreateBed vM_CreateBed = new VM_CreateBed();

            vM_CreateBed.BedCode = this._iBedServices.CreateNewCode();
            var languges = this._iReferenceServices.GetAllLanguage();

            vM_CreateBed.Languages = ConvertVM.Language_To_VMLanguage(languges);
            return(View(vM_CreateBed));
        }
        public ActionResult PerformCreateBed(string code)
        {
            VM_Bed bed = new VM_Bed
            {
                BedCode = code
            };
            var id = this._iBedServices.CreateNewBedReturnId(ConvertVM.VMBed_To_Bed(bed));

            return(Json(id));
        }
        public ActionResult Booking(int bedId)
        {
            var             bookings        = this._iBookingServices.GetBillBed(bedId, false).ToList();
            VM_BookingByBed vM_BookingByBed = new VM_BookingByBed();

            vM_BookingByBed.BedId    = bedId;
            vM_BookingByBed.Bookings = ConvertVM.Bill_To_VMBookingByBedInformationRow(bookings);

            return(View(vM_BookingByBed));
        }
        public ActionResult Booked(long id)
        {
            var       booked    = this._iBookingServices.GetBill(id);
            VM_Booked vM_Booked = ConvertVM.Bill_To_VMooked(booked);

            vM_Booked.BedName     = this._iBedServices.GetBedName(booked.BedId);
            vM_Booked.CusomerName = booked.Customer.LastMiddle + " " + booked.Customer.FirstName;
            //vM_Booked.Services = this._iServiceServices
            return(View(vM_Booked));
        }
        public ActionResult PerformAddServiceNameInLanguage(int serviceId, string value, int languageId)
        {
            VM_ServiceName serviceName = new VM_ServiceName
            {
                Name       = value,
                LanguageId = languageId,
                ServiceId  = serviceId
            };
            var id = this._iServiceServices.AddNameForService(ConvertVM.VMServiceName_To_ServiceName(serviceName));

            return(Json(id));
        }
        public ActionResult PerformAddBedNameInLanguage(int bedId, string value, int languageId)
        {
            VM_BedName bedName = new VM_BedName
            {
                Name       = value,
                LanguageId = languageId,
                BedId      = bedId
            };
            var id = this._iBedServices.AddNameForBed(ConvertVM.VMBedName_To_BedName(bedName));

            return(Json(id));
        }
        public ActionResult GetSalaryForEmployeeInMonth(long empId, int month = -1, int year = -1)
        {
            try
            {
                var rsl = "";
                if (month < 0 || month > 12 || year < 0)
                {
                    var allSalaries = ConvertVM.Salary_To_VMEmpSalaryPaying(this._iSalaryServices.GetSalariesForEmployee(empId).ToList());

                    foreach (var salary in allSalaries.ListEmpPaying)
                    {
                        var isPaid = salary.IsPaid;
                        rsl += "<tr>" +
                               "<td>" +
                               "<select class='input-sm disabled' data-val='true' data-val-required='The IsPaid field is required.' id='SalaryPaying_ListEmpPaying_0__IsPaid' name='SalaryPaying.ListEmpPaying[0].IsPaid'>" +
                               "<option " + (isPaid ? "selected = 'selected'" : "") + "  value='true'>Paid</option>" +
                               "<option " + (!isPaid ? "selected = 'selected'" : "") + "  value='false'>Un-paid</option>" +
                               "</select>" +
                               "</td>" +
                               "< td >" + salary.TimePay + "</td>" +
                               "<td>" + salary.TotalSalary + "</td>" +
                               "<td>" + salary.Description + "</td>" +
                               "</tr>";
                    }
                }
                else
                {
                    var salaries = ConvertVM.Salary_To_VMEmpSalaryPaying(this._iSalaryServices.GetAllSalariesForEmployee(empId, month, year).ToList());
                    foreach (var salary in salaries.ListEmpPaying)
                    {
                        var isPaid = salary.IsPaid;
                        var d      = decimal.Parse(salary.TotalSalary.ToString(), CultureInfo.InvariantCulture);
                        rsl += "<tr>" +
                               "<td>" +
                               "<select class='input-sm disabled' data-val='true' data-val-required='The IsPaid field is required.' id='" + salary.Id + "' name='" + salary.Id + "'>" +
                               "<option " + (isPaid ? "selected = 'selected'" : "") + "  value='true'>Paid</option>" +
                               "<option " + (!isPaid ? "selected = 'selected'" : "") + "  value='false'>Un-paid</option>" +
                               "</select>" +
                               "</td>" +
                               "<td>" + salary.TimePay.Value.ToString("yyyy MMM") + "</td>" +
                               "<td>" + d.ToString(CultureInfo.InvariantCulture) + "</td>" +
                               "<td>" + salary.Description + "</td>" +
                               "</tr>";
                    }
                }
                return(Json(rsl));
            }
            catch (Exception ex)
            {
                logger.Error("Error: [" + ex.Message + "]");
                return(View("ErrorAdminPage"));
            }
        }
 public ActionResult Salary(long empId, int month = -1, int year = -1)
 {
     logger.EnterMethod();
     try
     {
         if (month > 0 && month <= 12 && year > 0)
         {
             DateTime date        = new DateTime(year, month, 1);
             var      empSalaries = this._iSalaryServices.GetSalariesForStaffPreviewNearest(empId, date).ToList();
             if (empSalaries != null)
             {
                 var emp                 = this._iStaffServices.Get(empId);
                 var salaries            = empSalaries.ToList();
                 var empCountAllSalaries = this._iSalaryServices.TotalSalariesInPast(empId);
                 var model               = ConvertVM.VMSalary_Add_VMEmpSalaryPaying_Add_History(ConvertVM.Staff_To_VMSalary(emp),
                                                                                                new VM_EmpSalaryPaying()
                 {
                     ListEmpPaying = ConvertVM.Salary_To_VMSalaryPaying(salaries)
                 },
                                                                                                empCountAllSalaries);
                 return(View(model));
             }
         }
         else
         {
             var empSalaries = this._iSalaryServices.GetSalariesForStaffPreviewNearest(empId);
             if (empSalaries.ToList() != null)
             {
                 var emp                 = this._iStaffServices.Get(empId);
                 var salaries            = empSalaries.ToList();
                 var empCountAllSalaries = this._iSalaryServices.TotalSalariesInPast(empId);
                 var model               = ConvertVM.VMSalary_Add_VMEmpSalaryPaying_Add_History(ConvertVM.Staff_To_VMSalary(emp),
                                                                                                new VM_EmpSalaryPaying()
                 {
                     ListEmpPaying = ConvertVM.Salary_To_VMSalaryPaying(salaries)
                 },
                                                                                                empCountAllSalaries);
                 return(View(model));
             }
         }
         return(View("ErrorAdminPage"));
     }
     catch (Exception e)
     {
         logger.Error("Error: [" + e.Message + "]");
         return(View("ErrorAdminPage"));
     }
     finally
     {
         logger.LeaveMethod();
     }
 }
        public ActionResult PerformCreateService(string code, int hours, int minutes, decimal cost, bool isActive)
        {
            VM_Service service = new VM_Service
            {
                ServiceCode = code,
                TimeCost    = new VM_Time(hours, minutes),
                Cost        = cost,
                IsInUse     = isActive
            };
            var id = this._iServiceServices.CreateNewServiceReturnId(ConvertVM.VMService_To_Service(service));

            return(Json(id));
        }
        public ActionResult Salaries()
        {
            var vM_SalariesInMonth = new VM_SalariesInMonth();
            var months             = this._iSalaryServices.GetCollectionMonthPaid();

            foreach (var item in months)
            {
                var salary = new VM_Salaries
                {
                    Time     = item,
                    Salaries = ConvertVM.Salary_To_VMSalaryInfo(this._iSalaryServices.GetAllSalariesPaidInMonth(item))
                };
                vM_SalariesInMonth.MonthSalaries.Add(salary);
            }
            var a = vM_SalariesInMonth.MonthSalaries.Select(_ => _.Time.Year).Distinct();

            return(View(vM_SalariesInMonth));
        }
 public ActionResult Employee(int id = 1)
 {
     logger.EnterMethod();
     try
     {
         var vM_Staff = this._iStaffServices.Get(id);
         var vM_ContactInformation = this._iContactInformationServices.Get(id);
         return(PartialView("User", ConvertVM.VMStaff_Add_VM_ContactInformation_To_VMStaffInformation(vM_Staff, vM_ContactInformation)));
     }
     catch (Exception e)
     {
         logger.Error("Error: [" + e.Message + "]");
         return(View("ErrorAdminPage"));
     }
     finally
     {
         logger.LeaveMethod();
     }
 }
        public ActionResult CreateNewCustomerFromBooking(string code, string firstname, string lastname, string summary)
        {
            var vM_Customer = new VM_Customer
            {
                CustomerCode = code,
                FirstName    = firstname,
                LastMiddle   = lastname,
                Summary      = summary,
                Image        = "[nullimage]"
            };

            var id = this._iCustomerServices.InsertCustomerReturnId(ConvertVM.VMCustomer_To_Customer(vM_Customer));

            if (id > 0)
            {
                return(Json(new
                {
                    id = id,
                    name = vM_Customer.FullName
                }));
            }
            return(Json(-1));
        }
 /// <summary>
 /// Go to Service for admin
 /// </summary>
 /// <param name="language">Language pass by user, default is English</param>
 /// <returns>
 /// Page fit language.
 ///     If not found langue in settings, return page Error.
 /// </returns>
 public ActionResult AdminServices(string language = "en", int page = 1)
 {
     logger.EnterMethod();
     try
     {
         string lang = WebConfigurationManager.AppSettings[language];
         if (String.IsNullOrEmpty(lang))
         {
             logger.Error("Can't find value: [" + language + "] in Web.config");
             return(View("ErrorAdminPage"));
         }
         else
         {
             logger.Info("Found value: [" + lang + "] for: [" + language + "] input");
         }
         var allServices    = this._iServiceServices.GetServiceByPage(page).ToList();
         var nameOfServices = new List <string>();
         foreach (var item in allServices)
         {
             nameOfServices.Add(this._iServiceServices.GetServiceNameByLanguage(item.Id, lang));
         }
         logger.Info("Found [" + nameOfServices.Count() + "] names for [" + allServices.Count() + "] services");
         var listServices = SelfConvertVM.VM_ServiceAddName(ConvertVM.Service_To_VMService(allServices), nameOfServices);
         var ttPage       = this._iServiceServices.CountTotalPages();
         return(View(ConvertVM.ListServices_To_VMListServices(listServices, page, this._iServiceServices.CountTotalPages())));
     }
     catch (Exception ex)
     {
         logger.Error("Error: [" + ex.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();
            }
        }