public async Task <JsonResult> AjaxMethod(string name, string leave_id)
        {
            var currentuser   = User.Identity.Name;
            var currentuserId = _context.AllUser.Where(x => x.Email == currentuser).FirstOrDefault().id;



            int leave_id_int = int.Parse(leave_id);
            var leave        = _context.LeaveHistory.Include(x => x.AllUser).Include(x => x.leaveType).Where(x => x.leave_id == leave_id_int).FirstOrDefault();

            leave.RegistrarApproveStatus = name;
            leave.LeaveStatus            = name;
            leave.approved_id            = currentuserId;



            UserEmail userEmail = new UserEmail
            {
                ToEmail = leave.AllUser.Email,
            };
            var arr         = new List <KeyValuePair <string, string> >();
            var leavereason = new KeyValuePair <string, string>("{{leavereason}}", leave.LeaveReason);
            var leavestart  = new KeyValuePair <string, string>("{{leavestart}}", leave.StartFrome.ToString());
            var leaveend    = new KeyValuePair <string, string>("{{leaveend}}", leave.EndTill.ToString());
            var leavetype   = new KeyValuePair <string, string>("{{leavetype}}", leave.leaveType.LeaveType);
            var leavestatus = new KeyValuePair <string, string>("{{leavestatus}}", leave.LeaveStatus);

            //temp.Key = "username";
            //temp.Value = "*****@*****.**";
            arr.Add(leavereason);
            arr.Add(leavestart);
            arr.Add(leaveend);
            arr.Add(leavetype);
            arr.Add(leavestatus);
            userEmail.PlaceHolder = arr;
            await emailService.LeaveStatusChangeEmail(userEmail);

            if (name == "Accepted")
            {
                var allocation = _context.leaveAllocation.Where(x => x.id == leave.id && x.leaveTypeID == leave.leaveTypeID).FirstOrDefault();
                allocation.NoOfLeave -= leave.NoOfDay;
                _context.Update(allocation);
                _context.SaveChanges();
            }
            //try
            //{
            _context.Update(leave);
            await _context.SaveChangesAsync();

            //}
            //catch (Exception e)
            //{
            //    throw;
            //}



            return(Json(leave));
        }
        public bool addtoallocation(string email, string oldvalue, int noofday)
        {
            int sum = 0;
            var z   = _context.leaveAllocation.Include(x => x.leaveType).Include(x => x.AllUser)
                      .Where(x => x.leaveType.LeaveType == oldvalue && x.AllUser.Email == email).FirstOrDefault();

            z.NoOfLeave -= noofday;
            _context.Update(z);
            _context.SaveChanges();
            return(true);
        }
Exemple #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Dean_id,MobileNo,FirstName,LastName,Deparment,FreeLeave")] Dean dean)
        {
            if (id != dean.Dean_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dean);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DeanExists(dean.Dean_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dean));
        }
        public async Task <IActionResult> Edit(int id, [Bind("leave_id,LeaveStatus,HODApproveStatus,DeanApproveStatus,RegistrarApproveStatus,NoOfDay,LeaveReason,StartFrome,EndTill,id")] LeaveHistory leaveHistory)
        {
            if (id != leaveHistory.leave_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(leaveHistory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LeaveHistoryExists(leaveHistory.leave_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["id"] = new SelectList(_context.AllUser, "id", "id", leaveHistory.id);
            return(View(leaveHistory));
        }
Exemple #5
0
        public async Task <IActionResult> Edit(int id, [Bind("id,Email,MobileNo,MobileNo2,Name,LastName,MiddleName,Deparment,Role,Addreaddress,City,PaidLeave")] AllUser allUser)
        {
            if (id != allUser.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(allUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AllUserExists(allUser.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(allUser));
        }
Exemple #6
0
        public async Task <IActionResult> OwnProfile(OwnProfile ownProfile)
        {
            //var userLoginDetail = userManager.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();
            //var userdetail = _context.AllUser.Where(x => x.Email == userLoginDetail.Email).FirstOrDefault();
            if (ModelState.IsValid)
            {
                string  uniqueFileName = ProcessUploadedFile(ownProfile);
                AllUser allUser        = new AllUser
                {
                    id           = ownProfile.id,
                    LastName     = ownProfile.LastName,
                    Addreaddress = ownProfile.Addreaddress,
                    Email        = User.Identity.Name,
                    City         = ownProfile.City,
                    MiddleName   = ownProfile.MiddleName,
                    MobileNo     = ownProfile.MobileNo.ToString(),
                    MobileNo2    = ownProfile.MobileNo2.ToString(),
                    Name         = ownProfile.Name,
                    PaidLeave    = ownProfile_transfer.PaidLeave,
                    Deparment    = ownProfile_transfer.Department,
                    Role         = ownProfile_transfer.Role,
                    UserImage    = uniqueFileName
                };

                try
                {
                    _context.Update(allUser);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(controllerName: "common", actionName: "OwnProfile"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(View(ownProfile));
                }
            }

            return(View(ownProfile));
        }
        public async Task <IActionResult> UpdateLeave(int id, LeaveRequest leaveRequest, IFormFile file)
        {
            int leave_id = id;

            if (leave_id == 0)
            {
                return(NotFound());
            }
            var leaveHistory = _context.LeaveHistory.Include(l => l.AllUser)
                               .Where(m => m.leave_id == leave_id && m.AllUser.Email == User.Identity.Name).FirstOrDefault();

            if (leaveHistory == null)
            {
                return(NotFound());
                //return RedirectToAction("MyLeave", "Faculty");
            }
            int status = DateTime.Compare(leaveHistory.StartFrome, DateTime.Now);

            if (status <= 0)
            {
                return(RedirectToAction("MyLeave", "Faculty"));
            }
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (file != null)
                {
                    string uploadsFolder = Path.Combine(webHostEnvironment.WebRootPath, "file");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + file.FileName;
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        file.CopyTo(fileStream);
                    }
                }
                try
                {
                    var oldallocatedleave = _context.leaveAllocation.Include(x => x.leaveType).Where(x => x.id == leaveHistory.id && x.leaveTypeID == leaveHistory.leaveTypeID).FirstOrDefault();

                    var statusOfAllocation = convertleavetype(leaveRequest.LeaveType, oldallocatedleave.leaveType.LeaveType, (int)((leaveRequest.LeaveEndTill - leaveRequest.LeaveStartFrome).TotalDays), leaveHistory.NoOfDay);
                    if (!statusOfAllocation)
                    {
                        ModelState.AddModelError(string.Empty, "You can not request More than " + oldallocatedleave.NoOfLeave + leaveHistory.NoOfDay);
                        return(View(leaveRequest));
                    }
                    if (leaveHistory.LeaveStatus == "Approve")
                    {
                        readdleave(leaveHistory.leaveType.LeaveType, leaveHistory.NoOfDay);
                    }
                    leaveHistory.LeaveReason      = leaveRequest.LeaveReason;
                    leaveHistory.LeaveStatus      = "Pending";
                    leaveHistory.HODApproveStatus = "Pending";
                    leaveHistory.EndTill          = leaveRequest.LeaveEndTill;
                    leaveHistory.StartFrome       = leaveRequest.LeaveStartFrome;
                    leaveHistory.leaveTypeID      = Convert.ToInt32(leaveRequest.LeaveType);
                    leaveHistory.NoOfDay          = (int)((leaveRequest.LeaveEndTill - leaveRequest.LeaveStartFrome).TotalDays);
                    leaveHistory.Attachment       = uniqueFileName;
                    var HODuser = _context.AllUser.Where(x => x.Role == "HOD" && x.Deparment == leaveHistory.AllUser.Deparment).FirstOrDefault();
                    _context.Update(leaveHistory);
                    await _context.SaveChangesAsync();

                    UserEmail userEmail = new UserEmail
                    {
                        ToEmail = HODuser.Email,
                    };
                    var arr         = new List <KeyValuePair <string, string> >();
                    var temp        = new KeyValuePair <string, string>("{{username}}", leaveHistory.AllUser.Email);
                    var StaringDate = new KeyValuePair <string, string>("{{startfrome}}", leaveRequest.LeaveStartFrome.ToLongDateString());
                    var TillDate    = new KeyValuePair <string, string>("{{endtill}}", leaveRequest.LeaveEndTill.ToLongDateString());

                    //temp.Key = "username";
                    //temp.Value = "*****@*****.**";
                    arr.Add(temp);
                    arr.Add(StaringDate);
                    arr.Add(TillDate);
                    userEmail.PlaceHolder = arr;
                    await emailService.SendLeaveUpdateEmail(userEmail);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction("MyLeave", "Faculty"));
            }
            ;
            return(View());
        }