Exemple #1
0
        public HttpResponseMessage WithdrawApplication(HttpRequestMessage request, [FromUri] int applicationId)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (applicationId == 0)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, "No Application Selected");
                }

                string userId = User.Identity.GetUserId();

                AdApplication adApplication = adApplicationRespository.Get(applicationId);

                adApplication.Status = ApplicationStatus.Withdrawn;

                if (adApplication.AdApplicantId != userId)
                {
                    return request.CreateResponse(HttpStatusCode.Unauthorized);
                }

                adApplicationRespository.Update(adApplication);

                response = request.CreateResponse(HttpStatusCode.OK, adApplication);

                return response;
            }));
        }
        public object CheckUsing(int id)
        {
            var msg = new JMessage()
            {
                Error = false
            };
            AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);

            if (obj != null)
            {
                var appFunc = _context.AdAppFunctions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                var pms     = _context.AdPermissions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                if (appFunc != null || pms != null)
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_OBJ_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP"));
                }
            }
            else
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_NOT_CHECKED"), CommonUtil.ResourceValue("ADM_APP_LBL_APP"));
            }
            return(Json(msg));
        }
Exemple #3
0
        public HttpResponseMessage GetApplicationDetails(HttpRequestMessage request, [FromUri] int applicationId)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (applicationId == 0)
                {
                    return request.CreateResponse(HttpStatusCode.BadRequest, "No Application Selected");
                }

                string userId = User.Identity.GetUserId();

                AdApplicationDetailsModel adDetails = new AdApplicationDetailsModel();

                AdApplication adApplication = adApplicationRespository.Get(applicationId);

                if (adApplication.AdApplicantId != userId)
                {
                    return request.CreateResponse(HttpStatusCode.Unauthorized);
                }

                Ad ad = adRepository.Get(adApplication.AdId);

                adDetails.AdApplication = adApplication;
                adDetails.AdDetails = ad;

                response = request.CreateResponse(HttpStatusCode.OK, adDetails);

                return response;
            }));
        }
Exemple #4
0
        public Task SendDeniedMessage(AdApplication adApplication, Account userAccount)
        {
            Ad     ad = adRepository.Get(adApplication.AdId);
            string jobApplicationUnSuccessfulMessage = string.Format(@"Your Job Application to job {0} was unsuccesful, Please log on to http://www.jobmtaani.co.ke/#/profile to apply for more roles",
                                                                     ad.AdTitle);

            return(SendEmailMessage(userAccount.Email, jobApplicationUnSuccessfulMessage, "Job Mtaani Job Activity"));
        }
        public async Task <JsonResult> Update(AdApplication obj, IFormFile uploadIcon)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Update application");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var objUpdate = _context.AdApplications.SingleOrDefault(x => x.ApplicationId == obj.ApplicationId);
                var objOld    = CommonUtil.Clone(objUpdate);
                if (objUpdate.ApplicationCode != obj.ApplicationCode)
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_CODE_CHANGE"), CommonUtil.ResourceValue("ADM_APP_LBL_APP"));
                    //_logger.LogError(LoggingEvents.LogDb, "Update group user fail");
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Update application failed: Application code can't change", null, null, "Error");
                }
                else
                {
                    var iconUrl = objUpdate.Icon;
                    if (uploadIcon != null && uploadIcon.Length > 0)
                    {
                        var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "images\\appIcon");
                        if (!Directory.Exists(pathUpload))
                        {
                            Directory.CreateDirectory(pathUpload);
                        }

                        var fileName = obj.ApplicationCode + "-" + uploadIcon.FileName;
                        var filePath = Path.Combine(pathUpload, fileName);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await uploadIcon.CopyToAsync(stream);
                        }
                        iconUrl = "/images/appIcon/" + fileName;
                    }

                    objUpdate.Title       = obj.Title;
                    objUpdate.AppUrl      = obj.AppUrl;
                    objUpdate.Ord         = obj.Ord;
                    objUpdate.Icon        = iconUrl;
                    objUpdate.UpdatedDate = DateTime.Now;
                    var a = _context.SaveChanges();
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_SUCCESS"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Sửa khoản mục thành công";
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Update application successfully", objOld, objUpdate, "Update");
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_UPDATE_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Có lỗi khi sửa khoản mục";
                //_logger.LogError(LoggingEvents.LogDb, "Update application fail");
                _actionLog.InsertActionLog("VIB_APPLICATION", "Update application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }
        public async Task <JsonResult> Insert(AdApplication obj, IFormFile uploadIcon)
        {
            //_logger.LogInformation(LoggingEvents.LogDb, "Insert application");
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                var app = _context.AdApplications.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                if (app == null)
                {
                    var iconUrl = string.Empty;
                    if (uploadIcon != null && uploadIcon.Length > 0)
                    {
                        var pathUpload = Path.Combine(_hostingEnvironment.WebRootPath, "images\\appIcon");
                        if (!Directory.Exists(pathUpload))
                        {
                            Directory.CreateDirectory(pathUpload);
                        }

                        var fileName = obj.ApplicationCode + "-" + uploadIcon.FileName;
                        var filePath = Path.Combine(pathUpload, fileName);
                        using (var stream = new FileStream(filePath, FileMode.Create))
                        {
                            await uploadIcon.CopyToAsync(stream);
                        }
                        iconUrl  = "/images/appIcon/" + fileName;
                        obj.Icon = iconUrl;
                    }
                    obj.Status = 1;
                    _context.AdApplications.Add(obj);
                    var a = _context.SaveChanges();
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_SUCCESS"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Thêm khoản mục thành công";
                    //_logger.LogInformation(LoggingEvents.LogDb, "Insert application successfully");
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application successfully", null, obj, "Insert");
                }
                else
                {
                    msg.Error = true;
                    msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_EXIST"), CommonUtil.ResourceValue("APP_CODE"));
                    //_logger.LogError(LoggingEvents.LogDb, "Insert application fail");
                    _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application fail: Application code is exists", null, null, "Error");

                    return(Json(msg));
                }
            }
            catch (Exception ex)
            {
                msg.Error = true;
                msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_ADD_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); //"Có lỗi khi thêm khoản mục";
                //_logger.LogError(LoggingEvents.LogDb, "Insert application fail");
                _actionLog.InsertActionLog("VIB_APPLICATION", "Insert application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }
Exemple #7
0
        public async Task <HttpResponseMessage> ApplyToAd(HttpRequestMessage request, [FromBody] int adId)
        {
            return(await GetHttpResponseAsync(request, async() =>
            {
                HttpResponseMessage response = null;

                Ad ad = adRepository.Get(adId);

                string userId = User.Identity.GetUserId();

                AdApplication adApplication = new AdApplication()
                {
                    AdApplicantId = userId,
                    AdId = ad.AdId,
                    DateApplied = DateTime.Now,
                    Status = ApplicationStatus.Open
                };

                AdApplication existingAdApplication = adApplicationRespository.FindbyHireModel(userId, adId);

                if (existingAdApplication != null)
                {
                    if (existingAdApplication.Status == ApplicationStatus.Withdrawn)
                    {
                        existingAdApplication.Status = ApplicationStatus.Open;
                        adApplicationRespository.Update(existingAdApplication);

                        response = request.CreateResponse(HttpStatusCode.OK, existingAdApplication);
                        return response;
                    }
                    else
                    {
                        response = request.CreateResponse(HttpStatusCode.BadRequest, adApplication);

                        return response;
                    }
                }
                else
                {
                    adApplicationRespository.Add(adApplication);

                    Account applicant = UserManager.FindById(adApplication.AdApplicantId);
                    Account jobOwner = UserManager.FindById(ad.AccountId);

                    bool messagedelivered = await messageManager.NewJobApplicationMessage(adApplication, jobOwner, applicant);

                    response = request.CreateResponse(HttpStatusCode.OK, adApplication);

                    return response;
                }
            }));
        }
Exemple #8
0
        public HttpResponseMessage GetSuccesfulAdApplication(HttpRequestMessage request, [FromUri] int adId)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                AdApplication adapplication = adApplicationRespository.GetSuccesfulAdApplication(adId);

                response = request.CreateResponse(HttpStatusCode.OK, adapplication);

                return response;
            }));
        }
Exemple #9
0
        public async Task <bool> SendHiredMessage(AdApplication adApplication, Account jobOwner, Account hiredEmployee)
        {
            string jobApplicationSuccessfulMessage = string.Format(@"Hello {0},
Your Job Application to job number {1} was succesfull, Please log on to http://www.jobmtaani.co.ke/#/profile to view succesful applications, meanwhile expect a call from {2} on {3}",
                                                                   hiredEmployee.FirstName, adApplication.AdId, jobOwner.FirstName, jobOwner.PhoneNumber);

            string hiredEmployeeDetailsMessage = string.Format(@"Hello {0},
You have hired a new employee, call or text {1} on {2} to set up a meeting", jobOwner.FirstName,
                                                               hiredEmployee.FirstName, hiredEmployee.PhoneNumber);

            await SendEmailMessage(hiredEmployee.Email, jobApplicationSuccessfulMessage, "Job Mtaani Job Activity");
            await SendEmailMessage(jobOwner.Email, hiredEmployeeDetailsMessage, "Job Mtaani Job Activity");

            return(true);
        }
Exemple #10
0
        public async Task <bool> NewJobApplicationMessage(AdApplication adApplication, Account jobOwner, Account jobApplicant)
        {
            Ad ad = this.adRepository.Get(adApplication.AdId);

            string newJobApplicationMessage = string.Format(@"Hello {0},
Your have applied to job titled {1} Please log on to http://www.jobmtaani.co.ke/#/profile to all applications, we will notify you if the application is succesful", jobApplicant.FirstName,
                                                            ad.AdTitle);

            string newPotentialHireJobApplication = string.Format(@"Hello {0},
There has been a new application to the position you opened titled {1} log on to  http://www.jobmtaani.co.ke/#/profile to view all applications", jobOwner.FirstName,
                                                                  ad.AdTitle);

            await SendEmailMessage(jobApplicant.Email, newJobApplicationMessage, "Job Mtaani Job Activity");
            await SendEmailMessage(jobOwner.Email, newPotentialHireJobApplication, "Job Mtaani Job Activity");

            return(true);
        }
        public object Delete(int id)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                //_logger.LogInformation(LoggingEvents.LogDb, "Delete application");
                AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                if (obj != null)
                {
                    var appFunc = _context.AdAppFunctions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                    var pms     = _context.AdPermissions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                    if (appFunc != null || pms != null)
                    {
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_OBJ_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP"));
                        //_logger.LogError(LoggingEvents.LogDb, "Delete application fail");
                        _actionLog.InsertActionLog("VIB_APPLICATION", "Delete application: Unable to delete application is being used elsewhere", null, null, "Delete");
                    }
                    else
                    {
                        //_context.VIBApplications.Attach(obj);
                        _context.AdApplications.Remove(obj);
                        _context.SaveChanges();
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_SUCCESS"), CommonUtil.ResourceValue("ADM_APP_LBL_APP")); /*"Xóa khoản mục thành công."*/
                        //_logger.LogInformation(LoggingEvents.LogDb, "Delete application successfully");
                        _actionLog.InsertActionLog("VIB_APPLICATION", "Delete application successfully", obj, null, "Delete");
                    }
                }
                return(Json(msg));
            }
            catch (Exception ex)
            {
                //_logger.LogError(LoggingEvents.LogDb, "Delete application fail");
                _actionLog.InsertActionLog("VIB_APPLICATION", "Delete application failed: " + ex.Message, null, null, "Error");

                return(Json(new JMessage()
                {
                    Error = true, Title = String.Format(CommonUtil.ResourceValue("MSG_DELETE_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP"))                         /*"Có lỗi khi xóa khoản mục."*/
                }));
            }
        }
Exemple #12
0
        public HttpResponseMessage GetAdApplication(HttpRequestMessage request, [FromUri] int adId, [FromUri] string uid)
        {
            return(GetHttpResponse(request, () => {
                HttpResponseMessage response = null;

                if (!string.IsNullOrEmpty(uid))
                {
                    AdApplication adApplication = adApplicationRespository.FindbyHireModel(uid, adId);
                    response = request.CreateResponse(HttpStatusCode.OK, adApplication);
                }
                else
                {
                    AdApplication adApplication = adApplicationRespository.FindbyHireModel(User.Identity.GetUserId(), adId);
                    response = request.CreateResponse(HttpStatusCode.OK, adApplication);
                }

                return response;
            }));
        }
Exemple #13
0
        public Ad[] GetPageAds(string userId, int pageNumber, bool userOwned)
        {
            if (pageNumber == 0)
            {
                pageNumber = 1;
            }

            int pageSize = 10;
            int skip     = (pageNumber * pageSize) - pageSize;

            using (JobMtaaniDbContext entityContext = new JobMtaaniDbContext())
            {
                if (!userOwned)
                {
                    Ad[] ads = (from e in entityContext.AdSet
                                where e.AccountId != userId
                                orderby e.DateCreated descending
                                select e).Skip(skip).Take(pageSize).ToArray();

                    foreach (var ad in ads)
                    {
                        AdApplication adApplication = (from e in entityContext.AdApplicationSet
                                                       where e.AdId == ad.AdId && e.AdApplicantId == userId
                                                       select e).FirstOrDefault();
                        if (adApplication != null)
                        {
                            ad.AdApplied = true;
                        }
                    }

                    return(ads);
                }
                else
                {
                    return((from e in entityContext.AdSet
                            where e.AccountId == userId
                            orderby e.DateCreated descending
                            select e).Skip(skip).Take(pageSize).ToArray());
                }
            }
        }
Exemple #14
0
        public async Task <HttpResponseMessage> HireEmployee(HttpRequestMessage request, HireModel hireModel)
        {
            return(await GetHttpResponseAsync(request, async() =>
            {
                HttpResponseMessage response = null;

                string applicantId = UserManager.FindByName(hireModel.UserName).Id;
                AdApplication adApplication = adApplicationRespository.FindbyHireModel(applicantId, hireModel.AdId);
                Ad closedAd = adRepository.Get(hireModel.AdId);

                Account applicant = UserManager.FindById(applicantId);
                Account jobOwner = UserManager.FindById(closedAd.AccountId);

                if (adApplication.AdApplicantId == closedAd.AccountId)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, adApplication);
                    return response;
                }
                else
                {
                    adApplication.Status = ApplicationStatus.Accepted;
                    adApplication.DateClosed = DateTime.Now;
                    closedAd.AdClosed = true;

                    bool c = await messageManager.SendHiredMessage(adApplication, jobOwner, applicant);

                    adApplicationRespository.Update(adApplication);
                    adRepository.Update(closedAd);

                    await DenyOtherApplications(closedAd);

                    response = request.CreateResponse(HttpStatusCode.OK, adApplication);

                    return response;
                }
            }));
        }
        public object DeleteItems([FromBody] List <int> listId)
        {
            var msg = new JMessage()
            {
                Error = false
            };

            try
            {
                //_logger.LogInformation(LoggingEvents.LogDb, "Delete list application");
                List <int>           listRef         = new List <int>();
                List <int>           listDel         = new List <int>();
                List <AdApplication> listApplication = new List <AdApplication>();
                foreach (var id in listId)
                {
                    AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                    if (obj != null)
                    {
                        var pms     = _context.AdPermissions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                        var appFunc = _context.AdAppFunctions.FirstOrDefault(x => x.ApplicationCode == obj.ApplicationCode);
                        if (appFunc != null || pms != null)
                        {
                            listRef.Add(id);
                        }
                        else
                        {
                            listDel.Add(id);
                        }
                    }
                }
                if (listRef.Count > 0)
                {
                    if (listDel.Count > 0)
                    {
                        foreach (var id in listDel)
                        {
                            AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                            listApplication.Add(obj);
                            _context.Remove(obj);
                        }
                        _context.SaveChanges();
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_DEL_SUCCESS_LIST_ITEM_BUT_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete part of the application list successfully");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete part of the application list successfully", listApplication.ToArray(), null, "Delete");
                    }
                    else
                    {
                        msg.Error = true;
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_ERR_LIST_OBJ_REF"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete list application fail");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete list application fail", null, null, "Error");
                    }
                }
                else
                {
                    if (listDel.Count > 0)
                    {
                        foreach (var id in listDel)
                        {
                            AdApplication obj = _context.AdApplications.FirstOrDefault(x => x.ApplicationId == id);
                            listApplication.Add(obj);

                            _context.AdApplications.Attach(obj);
                            _context.AdApplications.Remove(obj);
                        }
                        _context.SaveChanges();
                        msg.Title = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_LIST_SUCCESS"),
                                                  CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                        //_logger.LogError(LoggingEvents.LogDb, "Delete part of the application list successfully");
                        _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete application list successfully", listApplication.ToArray(), null, "Delete");
                    }
                }
            }
            catch (Exception ex)
            {
                msg.Error  = true;
                msg.Object = ex;
                msg.Title  = String.Format(CommonUtil.ResourceValue("COM_MSG_DELETE_LIST_FAIL"), CommonUtil.ResourceValue("ADM_APP_LBL_APP").ToLower());
                //_logger.LogError(LoggingEvents.LogDb, "Delete list application fail");
                _actionLog.InsertActionLogDeleteItem("VIB_APPLICATION", "Delete list application failed: " + ex.Message, null, null, "Error");
            }
            return(Json(msg));
        }