Ejemplo n.º 1
0
        public UserModel RegisterAdmin(UserModel model)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                var userAcc = _service.GetUserByPhoneNumber(model.PhoneNumber);
                if (!Equals(userAcc, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_phone_number_already_existed");
                }

                userAcc = new user()
                {
                    phone_number = model.PhoneNumber,
                    email        = model.Email,
                    password     = Encrypt.EncodePassword(model.Password),
                    user_id      = 0,
                    role         = model.Role,
                    store_id     = 1,
                };
                _service.SaveUser(userAcc);
                var UserAccount = _service.GetUserByPhoneNumber(userAcc.phone_number);

                var UserProfile = new user_profile()
                {
                    user_profile_id = 0,
                    address         = "",
                    phone_number    = model.PhoneNumber,
                    birthday        = 0,
                    email           = model.Email,
                    full_name       = model.FullName,
                    gender          = 1,
                    role            = model.Role,
                    user_id         = UserAccount.user_id,
                    created_date    = ConvertDatetime.GetCurrentUnixTimeStamp(),
                };

                _service.SaveUserProfile(UserProfile);
                UserProfile = _service.GetUserProfileByPhoneNumber(model.PhoneNumber);


                var token = new TokenModel()
                {
                    Id          = UserAccount.user_id,
                    PhoneNumber = UserAccount.phone_number,
                    Role        = model.Role
                };

                scope.Complete();

                return(new UserModel()
                {
                    Id = UserAccount.user_id,
                    FullName = UserProfile.full_name,
                    PhoneNumber = UserAccount.phone_number,
                    UserCode = "UID_" + UserAccount.user_id.ToString().PadLeft(5, '0'),
                    Token = Encrypt.Base64Encode(JsonConvert.SerializeObject(token)),
                    Role = UserProfile.role
                });
            }
        }
Ejemplo n.º 2
0
        public ActionResult SaveSlide(List <SlideModel> list)
        {
            var type = 0;

            foreach (var model in list)
            {
                type = model.Type;
                var slide = _service.GetSlideById(model.Id);
                if (!Equals(model.ImageFile, null))
                {
                    var    fileName = "Slide_" + slide.slide_id + "_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.ImageFile.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.ImageFile.SaveAs(path);
                    slide.img = fileName;
                }
                slide.url = model.Url;
                _service.SaveSlide(slide);
            }
            if (type == 1)
            {
                return(RedirectToAction("SlideProject"));
            }
            if (type == 2)
            {
                return(RedirectToAction("SlideBlog"));
            }
            return(RedirectToAction("SlideHome"));
        }
Ejemplo n.º 3
0
        public contract GetCurrentParentContractByApartmentId(int apartmentId)
        {
            var currentTime = ConvertDatetime.GetCurrentUnixTimeStamp();

            return(ContractRepository
                   .FindBy(p => p.apartment_id == apartmentId && p.status == 1 && p.start_date.Value <= currentTime && currentTime <= p.end_date.Value && Equals(p.parent_id, null))
                   .Include(p => p.user_profile1.user_profile_note)
                   .Include(p => p.apartment.problems)
                   .FirstOrDefault());
        }
        public void MaidCreateProblem(ProblemModel model)
        {
            if (Request.Headers.TryGetValues("Token", out var values))
            {
                var token      = values.First();
                var tokenModel = JsonConvert.DeserializeObject <TokenModel>(Encrypt.Base64Decode(token));
                var maid       = _service.GetActiveMaidById(tokenModel.Id);
                if (Equals(maid, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_account_not_found");
                }

                var contract = _service.GetCurrentParentContractByApartmentId(model.ApartmentId);
                if (Equals(contract, null))
                {
                    ExceptionContent(HttpStatusCode.InternalServerError, "err_apartment_not_contract");
                }

                var problem = new problem
                {
                    created_date = ConvertDatetime.GetCurrentUnixTimeStamp(),
                    issue_id     = model.IssueId,
                    description  = model.Description,
                    problem_id   = 0,
                    status       = 0,
                    summary      = model.Summary,
                    type         = (int)ProblemType.Maid,
                    is_calendar  = false,
                    apartment_id = model.ApartmentId,
                    employee_id  = maid.employee_id,
                    contract_id  = contract.contract_id
                };
                _service.SaveProblem(problem);

                int idx       = 0;
                var listImage = new List <problem_image>();
                foreach (var item in model.ListImage)
                {
                    var img = new problem_image
                    {
                        problem_id = problem.problem_id,
                        img        = _service.SaveImage("~/Upload/problem/",
                                                        "problem_" + ConvertDatetime.GetCurrentUnixTimeStamp() + "_" + idx + ".png",
                                                        item.Img_Base64)
                    };
                    listImage.Add(img);
                    idx++;
                }
                _service.SaveListProblemImage(listImage);
            }
        }
Ejemplo n.º 5
0
        public ActionResult SaveSingleSlide(SlideModel model)
        {
            var slide = _service.GetSlideById(model.Id);

            if (!Equals(model.ImageFile, null))
            {
                var    fileName = "Slide_" + slide.slide_id + "_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.ImageFile.FileName);
                string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                model.ImageFile.SaveAs(path);
                slide.img = fileName;
            }
            //slide.url = model.Url;
            _service.SaveSlide(slide);
            return(RedirectToAction("SlideHome"));
        }
Ejemplo n.º 6
0
        public ActionResult BlogDetail(BlogModel model)
        {
            using (var scope = new TransactionScope())
            {
                var blog = _service.GetBlogById(model.Id);
                if (Equals(blog, null))
                {
                    blog = new blog()
                    {
                        blog_id      = 0,
                        created_date = ConvertDatetime.GetCurrentUnixTimeStamp()
                    };
                }
                if (!Equals(model.ImageFile, null))
                {
                    string fileName = "Blog_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.ImageFile.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.ImageFile.SaveAs(path);
                    blog.img = fileName;
                }
                blog.type = model.Type;
                _service.SaveBlog(blog);

                int idx = 0;
                foreach (var blogContent in model.ContentList)
                {
                    var content = _service.GetBlogContentById(blogContent.Id);
                    if (Equals(content, null))
                    {
                        content = new blog_content()
                        {
                            blog_content_id = 0,
                            blog_id         = blog.blog_id,
                            language        = idx
                        };
                    }
                    content.title       = blogContent.Title;
                    content.description = blogContent.Description;
                    content.content     = blogContent.Content;
                    _service.SaveBlogContent(content);
                    idx++;
                }

                scope.Complete();
            }
            return(RedirectToAction("Blog"));
        }
Ejemplo n.º 7
0
        public ActionResult FacilityDetail(FacilityModel model)
        {
            using (var scope = new TransactionScope())
            {
                var facility = _service.GetFacilityById(model.Id);
                if (Equals(facility, null))
                {
                    facility = new facility()
                    {
                        facility_id = 0,
                        status      = 1
                    };
                }
                if (!Equals(model.ImageFile, null))
                {
                    string fileName = "Facility_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.ImageFile.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.ImageFile.SaveAs(path);
                    facility.img = fileName;
                }
                _service.SaveFacility(facility);

                int idx = 0;
                foreach (var facilityContent in model.ContentList)
                {
                    var content = _service.GetFacilityContentById(facilityContent.Id);
                    if (Equals(content, null))
                    {
                        content = new facility_content()
                        {
                            facility_content_id = 0,
                            facility_id         = facility.facility_id,
                            language            = idx
                        };
                    }
                    content.name = facilityContent.Name;
                    _service.SaveFacilityContent(content);
                    idx++;
                }

                scope.Complete();
            }
            return(RedirectToAction("Facility"));
        }
Ejemplo n.º 8
0
        public ActionResult CareerDetail(CareerModel model)
        {
            using (var scope = new TransactionScope())
            {
                var career = _service.GetCareerById(model.Id);
                if (Equals(career, null))
                {
                    career = new career()
                    {
                        career_id    = 0,
                        created_date = ConvertDatetime.GetCurrentUnixTimeStamp()
                    };
                }
                career.type          = model.Type;
                career.city          = model.City;
                career.category_id   = model.CategoryId;
                career.salary_min    = model.SalaryMin;
                career.location      = model.Location;
                career.experied_date = model.ExpiredDate;
                _service.SaveCareer(career);

                int idx = 0;
                foreach (var careerContent in model.ContentList)
                {
                    var content = _service.GetCareerContentById(careerContent.Id);
                    if (Equals(content, null))
                    {
                        content = new career_content()
                        {
                            career_content_id = 0,
                            career_id         = career.career_id,
                            language          = idx
                        };
                    }
                    content.title   = careerContent.Title;
                    content.content = careerContent.Content;
                    _service.SaveCareerContent(content);
                    idx++;
                }

                scope.Complete();
            }
            return(RedirectToAction("Career"));
        }
        public void MaidTrackingIssue(ApartmentEmployeeModel model)
        {
            if (Request.Headers.TryGetValues("Token", out var values))
            {
                var token      = values.First();
                var tokenModel = JsonConvert.DeserializeObject <TokenModel>(Encrypt.Base64Decode(token));
                var maid       = _service.GetActiveMaidById(tokenModel.Id);
                if (Equals(maid, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_account_not_found");
                }

                var apartmentEmployee =
                    _service.GetLastApartmentEmployeeByApartmentIdAndEmployeeId(model.ApartmentId, maid.employee_id);
                apartmentEmployee.check_out_time = ConvertDatetime.GetCurrentUnixTimeStamp();
                apartmentEmployee.check_out_geo  = JsonConvert.SerializeObject(model.CheckOutGeo);
                apartmentEmployee.type           = model.Type;
                _service.SaveApartmentEmployee(apartmentEmployee);

                var apartmentIssues =
                    _service.GetListApartmentEmployeeIssueByApartmentEmployeeId(apartmentEmployee
                                                                                .apartment_employee_id);
                foreach (var item in apartmentIssues)
                {
                    _service.DeleteApartmentEmployeeIssue(item);
                }

                var listIssue = new List <apartment_employee_issue>();
                foreach (var item in model.ListIssue)
                {
                    var issue = new apartment_employee_issue
                    {
                        apartment_employee_id = apartmentEmployee.apartment_employee_id,
                        issue_id = item.IssueId,
                        apartment_employee_issue_id = 0,
                        is_complete = item.IsComplete
                    };
                    listIssue.Add(issue);
                }
                _service.SaveListApartmentEmployeeIssue(listIssue);
            }
        }
Ejemplo n.º 10
0
        public void CreateContract(ContractModel model)
        {
            var Contract = _service.GetContractById(0);
            var Product  = _service.GetProductById(model.ProductId);

            if (!Equals(Contract, null))
            {
                ExceptionContent(HttpStatusCode.InternalServerError, "contract_exist");
            }



            Contract = new contract()
            {
                address             = "",
                contract_id         = 0,
                employee_id         = model.EmployeeId,
                note                = model.Note,
                ppm_local           = Product.ppm_local,
                ppm_mobile          = Product.ppm_mobile,
                ppm_std             = Product.ppm_std,
                product_id          = model.ProductId,
                price               = model.Price,
                product_name        = Product.product_name,
                product_time_used   = Product.time_used,
                product_type        = Product.time_type,
                security_deposit    = _service.GetSecurityDepositByProductId(model.ProductId),
                signing_date        = ConvertDatetime.GetCurrentUnixTimeStamp(),
                status              = 1,
                store_id            = model.StoreId,
                time_used_available = Product.time_used,
                user_id             = model.UserId,
                start_date          = model.StartDate,
                end_date            = ConvertDatetime.GetEndDateWithMonthUsed(model.StartDate, Product.month_available),
            };
            _service.SaveContract(Contract);
        }
Ejemplo n.º 11
0
        public ActionResult ProjectDetail(ProjectModel model)
        {
            using (var scope = new TransactionScope())
            {
                var project = _service.GetProjectById(model.Id);
                if (Equals(project, null))
                {
                    project = new project()
                    {
                        project_id = 0,
                        status     = 1
                    };
                }

                project.type      = model.Type;
                project.address   = model.Address;
                project.latitude  = model.Latitude;
                project.longitude = model.Longitude;
                if (!Equals(model.ImageFile, null))
                {
                    string fileName = "Project_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.ImageFile.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.ImageFile.SaveAs(path);
                    project.img = fileName;
                }
                if (!Equals(model.Slide1File, null))
                {
                    string fileName = "Project_Slide1_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.Slide1File.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.Slide1File.SaveAs(path);
                    project.slide_1 = fileName;
                }
                if (!Equals(model.Slide2File, null))
                {
                    string fileName = "Project_Slide2_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.Slide2File.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.Slide2File.SaveAs(path);
                    project.slide_2 = fileName;
                }
                if (!Equals(model.Slide3File, null))
                {
                    string fileName = "Project_Slide3_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.Slide3File.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.Slide3File.SaveAs(path);
                    project.slide_3 = fileName;
                }
                if (!Equals(model.LogoFile, null))
                {
                    string fileName = "Project_Logo_" + ConvertDatetime.GetCurrentUnixTimeStamp() + Path.GetExtension(model.LogoFile.FileName);
                    string path     = Path.Combine(Server.MapPath("~/Upload"), fileName);
                    model.LogoFile.SaveAs(path);
                    project.logo = fileName;
                }
                _service.SaveProject(project);

                int idx = 0;
                foreach (var projectContent in model.ContentList)
                {
                    var content = _service.GetProjectContentById(projectContent.Id);
                    if (Equals(content, null))
                    {
                        content = new project_content()
                        {
                            project_content_id = 0,
                            project_id         = project.project_id,
                            language           = idx
                        };
                    }
                    content.name        = projectContent.Name;
                    content.description = projectContent.Description;
                    _service.SaveProjectContent(content);
                    idx++;
                }

                foreach (var overview in model.OverviewList)
                {
                    foreach (var overviewContent in overview.ContentList)
                    {
                        var content = _service.GetProjectOverviewById(overviewContent.Id);
                        if (Equals(content, null))
                        {
                            content = new project_overview()
                            {
                                project_overview_id = 0,
                                project_id          = project.project_id,
                                language            = overviewContent.Language
                            };
                        }

                        content.content = overviewContent.Content;
                        _service.SaveProjectOverview(content);
                    }
                }

                _service.DeleteAllProjectFacilities(project.project_facility.ToList());
                foreach (var item in model.FacilityList)
                {
                    if (item.Selected)
                    {
                        var fac = new project_facility()
                        {
                            project_facility_id = 0,
                            project_id          = project.project_id,
                            facility_id         = item.Id
                        };
                        _service.SaveProjectFacility(fac);
                    }
                }

                scope.Complete();
            }

            return(RedirectToAction("Project"));
        }
        public ApartmentModel GetApartmentByCode(ApartmentEmployeeModel model)
        {
            IEnumerable <string> values;

            if (Request.Headers.TryGetValues("Token", out values))
            {
                var token      = values.First();
                var tokenModel = JsonConvert.DeserializeObject <TokenModel>(Encrypt.Base64Decode(token));
                var maid       = _service.GetActiveMaidById(tokenModel.Id);
                if (Equals(maid, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_email_or_pass");
                }

                var apartment = _service.GetApartmentByCode(model.ApartmentCode);
                if (Equals(apartment, null))
                {
                    ExceptionContent(HttpStatusCode.InternalServerError, "err_apartment_not_found");
                }

                var contract = _service.GetCurrentParentContractByApartmentId(apartment.apartment_id);
                if (Equals(contract, null))
                {
                    ExceptionContent(HttpStatusCode.InternalServerError, "err_apartment_not_contract");
                }

                var contractEmployee =
                    _service.GetContractEmployeeByContractIdAndEmployeeId(contract.contract_id, maid.employee_id);
                if (Equals(contractEmployee, null) || contractEmployee.status != 1 || !Equals(contractEmployee.to_date, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_not_authorize");
                }

                var apartmentEmployee =
                    _service.GetLastApartmentEmployeeNotCheckOutByEmployeeId(maid.employee_id);
                if (!Equals(apartmentEmployee, null))
                {
                    ExceptionContent(HttpStatusCode.Unauthorized, "err_not_complete_check");
                }

                apartmentEmployee = new apartment_employee
                {
                    apartment_employee_id = 0,
                    check_in_time         = ConvertDatetime.GetCurrentUnixTimeStamp(),
                    check_in_geo          = JsonConvert.SerializeObject(model.CheckInGeo),
                    contract_id           = contract.contract_id,
                    employee_id           = maid.employee_id,
                    status = 1
                };
                _service.SaveApartmentEmployee(apartmentEmployee);

                return(new ApartmentModel
                {
                    Id = apartment.apartment_id,
                    Address = contract.address,
                    Building = contract.building,
                    NoApartment = contract.no_apartment,
                    Project = !Equals(apartment.apartment_id, null) ? new ProjectModel
                    {
                        Name = apartment.project.project_content.FirstOrDefault(p => p.language == 0).name
                    } : new ProjectModel(),
                    Resident = new UserProfileModel
                    {
                        FullName = contract.resident_name,
                        Phone = contract.resident_phone,
                        Id = contract.user_profile1.user_profile_id,
                        NoteList = contract.user_profile1.user_profile_note.Select(p => new UserProfileNoteModel
                        {
                            Id = p.user_profile_note_id,
                            CreatedDate = p.created_date,
                            Note = p.note
                        }).ToList()
                    },
                    PassWifi = contract.pass_wifi,
                    WifiName = contract.wifi_name,
                    PassDoor = contract.pass_door,
                    WorkHour = contractEmployee.work_hour,
                    WorkDate = contractEmployee.work_date.Split(',').ToList(),
                    Maid = new EmployeeModel
                    {
                        FirstName = maid.first_name,
                        LastName = maid.last_name
                    },
                    Area = contract.area,
                    NoBedRoom = contract.no_bedroom
                });
            }
            return(new ApartmentModel());
        }