public IHttpActionResult AddDefaultAllocation() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; DefaultAllocation alloc = new DefaultAllocation(); alloc.Client_Id = Convert.ToInt32(form.Get("Client")); alloc.Doctor_Id = Convert.ToInt32(form.Get("Doctor")); alloc.Employee_Id = Convert.ToInt32(form.Get("Employee")); alloc.JobLevel = form.Get("JobLevel"); alloc.LastModified = DateTime.Now; alloc.Accuracy = Convert.ToInt32(form.Get("Accuracy")); alloc.Pages = Convert.ToInt32(form.Get("NoOfPages")); alloc.Inactive = false; db.DefaultAllocations.Add(alloc); db.SaveChanges(); } return(Ok()); } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult UpdateEmployeeLeave() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; LeaveRecord leave = new LeaveRecord(); leave.EmpId = form.Get("empId"); leave.LeaveDate = Convert.ToDateTime(form.Get("leaveDate")); leave.UpdatedBy = User.Identity.GetUserId(); leave.LeaveType = form.Get("leaveType"); db.LeaveRecords.Add(leave); db.SaveChanges(); return(Ok()); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An errorr occured, please try again later")); } }
public async Task <IHttpActionResult> UpdateDefaultAlloc(int defaultAllocId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; DefaultAllocation defaultAlloc = db.DefaultAllocations.Find(defaultAllocId); defaultAlloc.Client_Id = Convert.ToInt32(form.Get("Client")); defaultAlloc.Doctor_Id = Convert.ToInt32(form.Get("Doctor")); defaultAlloc.Employee_Id = Convert.ToInt32(form.Get("Employee")); defaultAlloc.JobLevel = form.Get("JobLevel"); defaultAlloc.Pages = Convert.ToInt32(form.Get("NoOfPages")); defaultAlloc.Accuracy = Convert.ToInt32(form.Get("Accuracy")); defaultAlloc.LastModified = DateTime.Now; defaultAlloc.Inactive = Convert.ToBoolean(form.Get("IsInActive")); db.Entry(defaultAlloc).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok()); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public async Task <IHttpActionResult> PopulateEmptyAddresses() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var emptyAddressLocations = db.EmployeeAttendanceLogs.Where(x => x.Address == null).ToList(); foreach (var location in emptyAddressLocations) { try { string latlon = location.Latitude + "," + location.Longitude; XmlDocument xDoc = new XmlDocument(); xDoc.Load("https://maps.googleapis.com/maps/api/geocode/xml?latlng=" + latlon + "&key=AIzaSyCPbyemMRyuWmR7yiD-nIwXaaeZaw-jK9o"); XmlNodeList xNodelst = xDoc.GetElementsByTagName("result"); XmlNode xNode = xNodelst.Item(0); location.Address = xNode.SelectSingleNode("formatted_address").InnerText; db.Entry(location).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } catch { } } } return(Content(HttpStatusCode.OK, "Success")); } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetDeptWiseCategories() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var overallCategories = db.GetCategories().ToList(); var departmentsInfo = overallCategories.GroupBy(x => x.DepartmentId).Select(x => x.First()).Select(x => new { x.DepartmentId, x.Department, Categories = overallCategories.Where(y => y.DepartmentId == x.DepartmentId).GroupBy(y => y.CategoryId).Select(y => y.First()).Select(y => new { y.CategoryId, y.CategoryName, SubCategories = overallCategories.Where(z => z.CategoryId == y.CategoryId).GroupBy(z => z.SubCategoryId).Select(z => z.First()).Select(z => new { z.SubCategoryId, Name = z.SubCategory, z.Points, z.PointsLogId }).OrderBy(z => z.Name).ToList() }).OrderBy(y => y.CategoryName).ToList() }).OrderBy(x => x.Department).ToList(); return(Content(HttpStatusCode.OK, new { departmentsInfo })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public static string GenerateTaskId() { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var activitiesCount = db.Activities.Count(); if (activitiesCount > 0) { var lastActivity = db.Activities.OrderByDescending(x => x.CreatedDate).FirstOrDefault().TaskId; int count = Convert.ToInt32(lastActivity.Split('-')[1]); GenerateNewNumber: var taskId = "MAX-" + (count + 1).ToString("0000"); if (db.Activities.Any(x => x.TaskId == taskId)) { count++; goto GenerateNewNumber; } return(taskId); } else { var taskId = "MAX-0001"; return(taskId); } } }
public async Task <IHttpActionResult> GetDefaultEmp(int defaultAllocId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { DefaultAllocation da = await db.DefaultAllocations.FindAsync(defaultAllocId); var defaultAlloc = new DefaultAllocationsModel(); defaultAlloc.Client_Id = da.Client_Id; defaultAlloc.Client = da.Client.ShortName; defaultAlloc.Doctor_Id = da.Doctor_Id; defaultAlloc.Doctor = da.Doctor.FirstName + " " + da.Doctor.LastName; defaultAlloc.Employee_Id = da.Employee_Id; defaultAlloc.Employee = da.Employee.FirstName + " " + da.Employee.LastName; defaultAlloc.NoOfPages = da.Pages; defaultAlloc.Accuracy = da.Accuracy; defaultAlloc.JobLevel = da.JobLevel; defaultAlloc.Inactive = da.Inactive; return(Content(HttpStatusCode.OK, new { defaultAlloc })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An errror occured, please try again later")); } }
public IHttpActionResult AddClientTicketResponse() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; ActivitiesLog actLog = new ActivitiesLog(); actLog.AssignedBy = User.Identity.GetUserId(); actLog.AssignedTo = form.Get("assignedTo"); actLog.Status = "Pending"; actLog.Description = form.Get("description"); actLog.TaskDate = MasterDataController.GetIndianTime(DateTime.Now); actLog.TaskId = form.Get("taskId"); db.ActivitiesLogs.Add(actLog); db.SaveChanges(); return(Ok()); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetDispatchedStockDetails(int projectId, int itemId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var stock = db.Items.Where(x => x.ProjectId == projectId && x.ItemModelId == itemId).ToList(); List <ItemDetails> items = new List <ItemDetails>(); for (int i = 0; i < stock.Count(); i++) { ItemDetails item = new ItemDetails(); item.SerialNumber = stock[i].SerialNumber; item.MacAddress = stock[i].MACAddress; item.StockOutDate = stock[i].StockOutDate; item.ManufacturedDate = stock[i].ManufacturedDate; items.Add(item); } return(Content(HttpStatusCode.OK, new { items })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetProjects(string clientId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var projects = db.Opportunities.Where(x => x.Client_Id == clientId && x.Status == "Accepted").Select(x => new { value = x.Id, label = x.OpportunityName }).OrderBy(x => x.label).ToList(); var client = db.Clients.Where(x => x.AspNetUserId == clientId).FirstOrDefault(); if (client != null) { var projectLocation = db.ClientLocations.Where(x => x.Client_Id == client.Id).Select(x => new { label = x.AddressLine1 + " " + x.AddressLine2 + "," + x.City.Name + "," + x.State.Name + "," + x.Country.Name }).FirstOrDefault(); var ProjectWithLoc = db.Opportunities.Where(x => x.Client_Id == clientId && x.Status == "Accepted").Select(x => new { value = x.Id, label = x.OpportunityName + " ( " + projectLocation.label + " )" }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { projects, ProjectWithLoc })); } else { return(Content(HttpStatusCode.OK, new { projects })); } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, Please try again later")); } }
public IHttpActionResult GetClientEmployee(int empId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { /* Get employee having Id as empId from database */ var Employee = (from emp in db.ClientEmployees where emp.Id == empId select emp).FirstOrDefault(); var clientEmp = new ClientEmployeeModel(); clientEmp.Client_Id = Employee.Client_Id; clientEmp.client = Employee.Client.ShortName; clientEmp.FirstName = Employee.FirstName; clientEmp.LastName = Employee.LastName; clientEmp.MiddleName = Employee.MiddleName; clientEmp.PhoneNumber = Employee.PrimaryPhone; clientEmp.SecondaryNumber = Employee.SecondaryPhone; clientEmp.Email = Employee.Email; clientEmp.Fax = Employee.Fax; clientEmp.Department = Employee.Department; clientEmp.ImageOne = Employee.ImageOne; clientEmp.ImageTwo = Employee.ImageTwo; /* return an object of clientEmployee */ return(Content(HttpStatusCode.OK, new { clientEmp })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult AddEmpPayScale(int EmpId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; EmployeePayscale emp = db.EmployeePayscales.Where(x => x.Emp_Id == EmpId).FirstOrDefault(); //EmployeePayscale empPayScale = new EmployeePayscale(); emp.BankAccNo = form.Get("AccountNumber"); emp.BankAccName = form.Get("AccountName"); emp.BankBranch = form.Get("BranchName"); emp.BankName = form.Get("BankName"); emp.Gross = Convert.ToInt32(form.Get("CTC")); db.Entry(emp).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Ok()); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occureed, please try again later")); } }
// used in mrs public IHttpActionResult GetEmployees(int?orgId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { if (orgId != null) { var employees = db.Employees.Where(x => x.Active == true && x.OrgId == orgId && x.Role_Id != "4").Select(x => new { value = x.Id, label = x.FirstName + " " + x.LastName }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } else { // var orgName = db.Organisations.Where(x => x.Id == orgId).Select(x => x.OrgName).FirstOrDefault(); var employees = db.Employees.Where(x => x.Active == true && x.Role_Id != "4").Select(x => new { value = x.Id, label = x.FirstName + " " + x.LastName + "( " + x.Organisation.OrgName + " )" }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, Please try again later!")); } }
public IHttpActionResult GetEmpPayScale(int EmpId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { EmployeePayScaleModel empPayScale = new EmployeePayScaleModel(); var payScaleId = db.EmployeePayscales.Where(x => x.Emp_Id == EmpId).FirstOrDefault().Id; var empPay = db.EmployeePayscales.Find(payScaleId); empPayScale.AccountName = empPay.BankAccName; empPayScale.AccountNumber = empPay.BankAccNo; empPayScale.BankName = empPay.BankName; empPayScale.BranchName = empPay.BankBranch; empPayScale.CTC = empPay.Gross; return(Content(HttpStatusCode.OK, new { empPayScale })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured please try again later")); } }
public IHttpActionResult GetClientProjects(string clientId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var clientProjects = (from opp in db.Opportunities where (opp.Client_Id == clientId && opp.ActualCompletedDate == null && (opp.Status == "Accepted" || opp.Status == "InProcess")) select(new { value = opp.Id, label = opp.OpportunityName + " ( " + (db.ClientLocations.Where(x => x.Id == opp.Location_Id). Select(x => x.AddressLine1 + ", " + x.City.Name + " ," + x.City.State.Name + " ," + x.City.State.Country.Name + " ," + x.ZIP).FirstOrDefault() ) + " )" })).ToList(); return(Content(HttpStatusCode.OK, new { clientProjects })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetClientsWithAspNetUserId(int?orgId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { /* Get List of client from clients table */ if (orgId == null) { var clients = db.Clients.Where(x => x.Active == true).Select(x => new { value = x.AspNetUserId, label = x.ShortName + " ( " + x.Organisation.OrgName + " )", Id = x.Id }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { clients })); } else { var clients = db.Clients.Where(x => x.OrgId == orgId && x.Active == true).Select(x => new { value = x.AspNetUserId, label = x.ShortName, Id = x.Id }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { clients })); } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public static string RandomString(int length, int OrgId, int createdBy, bool role) { Random generator = new Random(); var r = generator.Next(1000, 10000).ToString(); gotoRandom: using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { if (role) { var prefix = createdBy + "-"; var taskId = prefix + r; var exists = db.Activities.Where(x => x.TaskId == taskId).FirstOrDefault(); if (exists != null) { goto gotoRandom; } return(taskId); } else { var prefix = db.Organisations.Where(x => x.Id == OrgId).FirstOrDefault().EmpPrefix; var taskId = prefix + r; var exists = db.Activities.Where(x => x.TaskId == taskId).FirstOrDefault(); if (exists != null) { goto gotoRandom; } return(taskId); } } }
public async Task <IHttpActionResult> SaveNotificationToken() { try { var userId = User.Identity.GetUserId(); if (userId != null) { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var employee = db.Employees.Where(x => x.AspNetUserId == userId).FirstOrDefault(); if (employee != null) { employee.NotificationToken = HttpContext.Current.Request.Form.Get("Token"); db.Entry(employee).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); } } } return(Ok()); } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occoured, please try again!")); } }
public IHttpActionResult GetMyReport(DateTime?fromDate, DateTime toDate, string client, string status, int?priority, string taskId, int?catId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var employee = User.Identity.GetUserId(); var overallReport = db.LogReport(employee, client, fromDate, toDate, status, priority, taskId, catId).OrderBy(x => x.CreatedDate).ToList(); var myActivityReport = overallReport.GroupBy(x => x.TaskId).Select(x => x.First()).Select(x => new { x.TaskId, x.CreatedDate, Creator = x.CreatedBy, x.Client, x.Department, x.Project, x.ProjectLocation, x.Quantity, x.Category, x.Priority, x.SubCategory, x.EDOC, CreatedBy = x.CreatedById, TaskOwner = x.TaskOwnerId, x.Status, x.CompletedDate, x.Subject, x.Description, Notifications = 0, HoursWorked = overallReport.Where(y => y.TaskId == x.TaskId).Sum(y => (decimal?)y.TaskLogHoursWorked) ?? 0, ExpectedStartDate = overallReport.Where(y => y.TaskId == x.TaskId).GroupBy(y => y.TaskLogId).Select(y => y.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(), TaskLog = overallReport.Where(y => y.TaskId == x.TaskId).GroupBy(y => y.TaskLogDate).Select(y => y.First()).Select(y => new { y.TaskLogId, y.TaskLogTaskId, y.TaskLogDate, y.TaskLogDescription, y.TaskLogQuantityWorked, y.TaskLogStartDate, y.TaskLogEndDate, y.TaskLogBudgetedHours, y.TaskLogHoursWorked, y.TaskLogAssignedTo, y.TaskLogAssignedToId, y.TaskLogAssignedBy, y.TaskLogAssignedById, y.TaskLogStatus }).OrderBy(y => y.TaskLogDate).ToList() }).ToList(); return(Content(HttpStatusCode.OK, new { myActivityReport })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetTicketLog(string taskId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var clientTicketLog = db.GetTicketLog(taskId).ToList(); List <ClientTicketLog> ticketLogList = new List <ClientTicketLog>(); if (clientTicketLog.Count > 0) { for (int i = 0; i < clientTicketLog.Count; i++) { ClientTicketLog ticketLog = new ClientTicketLog(); ticketLog.CreatedBy = clientTicketLog[i].AssignedBy; ticketLog.Description = clientTicketLog[i].Description; ticketLog.Status = clientTicketLog[i].Status; ticketLog.TaskDate = clientTicketLog[i].TaskDate; ticketLog.ActivityLogId = clientTicketLog[i].ActivityLogId; ticketLog.Department = clientTicketLog[i].Department; var atchmts = db.ActivityAttachments.Where(x => x.ActivityId == ticketLog.ActivityLogId).ToList(); // ticketLog.Attachments = atchmts.Select(x => x.AttachmentURL).ToArray(); List <Attachment> attachments = new List <Attachment>(); if (atchmts.Count > 0) { foreach (var at in atchmts) { Attachment att = new Attachment(); att.AttachmentUrl = at.AttachmentURL; att.FileName = at.Name; att.Id = at.Id; attachments.Add(att); } // ticketLog.Attachments= db.ActivityAttachments.Where(x => x.ActivityId == ticketLog.ActivityLogId).Select(x => new { value = x.AttachmentURL, label = x.Name }).ToList(); } ticketLog.Attachments = attachments; ticketLogList.Add(ticketLog); } } var clientId = User.Identity.GetUserId(); var lastRespondedEmp = db.GetTicketLog(taskId).Where(x => x.AssignedById != clientId).OrderByDescending(x => x.TaskDate).FirstOrDefault(); return(Content(HttpStatusCode.OK, new { ticketLogList, lastRespondedEmp })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetDoctor(int doctor_Id) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var docDetails = db.Doctors.Where(x => x.Id == doctor_Id).FirstOrDefault(); var specialities = docDetails.Specialties.Select(x => new { value = x.Id, label = x.Name }).OrderBy(x => x.label).ToList();; var doctor = new DoctorsModel(); if (doctor != null) { doctor.Salutation = docDetails.Salutation; doctor.FirstName = docDetails.FirstName; doctor.MiddleName = docDetails.MiddleName; doctor.LastName = docDetails.LastName; doctor.PhoneNumber = docDetails.PrimaryPhone; doctor.SecondaryNumber = docDetails.SecondaryPhone; doctor.Email = docDetails.Email; doctor.Client_Id = docDetails.Client_Id; doctor.Client = docDetails.Client.Name; doctor.Addressline1 = docDetails.AddressLine1; doctor.AddressLine2 = docDetails.AddressLine2; if (docDetails.City_Id != 0) { doctor.City_Id = docDetails.City_Id; doctor.City = docDetails.City.Name; doctor.State_Id = docDetails.City.State_Id; doctor.State = docDetails.City.State.Name; doctor.Country_Id = docDetails.City.State.Country_Id; doctor.Country = docDetails.City.State.Country.Name; } doctor.Zip = docDetails.ZIP; doctor.DictationMode = docDetails.DictationMode; doctor.JobLevel = docDetails.JobLevel; doctor.MacroPercent = docDetails.MacroPercent; doctor.IdigitalId = docDetails.IdigitalId; doctor.IdigitalAuthorId = docDetails.IdigitalAuthorId; doctor.DoctorGroup_Id = docDetails.DoctorGroup_Id; doctor.DoctorGroup = docDetails.DoctorGroup.Name; doctor.VoiceGrade = docDetails.VoiceGrade; doctor.IsActive = docDetails.Active; } return(Content(HttpStatusCode.OK, new { doctor, specialities })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetEmployeeDayWiseReport(string empId, string clientId, DateTime fromDate, DateTime toDate, string status, int?priority, string taskId, int?catId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var overallReport = db.LogReport(empId, clientId, fromDate, toDate, status, priority, taskId, catId).ToList(); // var overallReport = db.EmployeeDayReport(empId, clientId, fromDate, toDate, status, priority, taskId).OrderBy(x=>x.TaskLogDate).ToList(); var employeeReport = overallReport.Where(x => x.TaskLogDate >= fromDate.Date && x.TaskLogDate <= toDate.Date.AddDays(1) && x.TaskLogAssignedById == empId).Select(x => new { x.TaskId, x.CreatedDate, x.CreatedBy, x.Subject, x.Category, x.Department, x.CompletedDate, x.EDOC, x.Priority, x.Project, x.ProjectLocation, x.Client, x.SubCategory, TaskStatus = x.Status, x.Description, x.TaskOwner, x.TaskType, x.TaskLogDate, x.TaskLogDescription, x.TaskLogStatus, HoursWorked = x.TaskLogHoursWorked, QuantityWorked = x.TaskLogQuantityWorked, TotalHoursWorked = overallReport.Where(z => z.TaskId == x.TaskId).Sum(z => (decimal?)z.TaskLogHoursWorked) ?? 0, StartAndEndDate = overallReport.Where(z => z.TaskId == x.TaskId).GroupBy(z => z.TaskLogId).Select(z => z.First()).ToList().Where(tl => tl.TaskLogStartDate != null).FirstOrDefault(), TaskLog = overallReport.Where(y => y.TaskId == x.TaskId).GroupBy(y => y.TaskLogId).Select(y => y.First()).Select(y => new { y.TaskLogId, y.TaskLogDate, y.TaskLogAssignedBy, y.TaskLogAssignedTo, y.TaskLogHoursWorked, y.TaskLogQuantityWorked, y.TaskLogDescription, y.TaskLogStatus }).OrderBy(y => y.TaskLogDate).ToList() }).ToList(); return(Content(HttpStatusCode.OK, new { employeeReport })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetStockRequests(string client, int?project, DateTime?fromDate, DateTime?toDate, string status, int?page, int?count) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var user = ""; int?TotalCount = 0; var employeeId = User.Identity.GetUserId(); var emp = db.Employees.Where(x => x.AspNetUserId == employeeId).FirstOrDefault(); if (emp != null) { if (emp.Role_Id != "8") { user = User.Identity.GetUserId(); } else { user = null; } } else { user = null; } var stockRequests = db.GetStockRequests(user, client, project, fromDate, toDate, status, page, count).ToList(); var stockMangers = db.StockManagers.ToList(); var exists = stockMangers.Find(x => x.AspNetUserId == user); if (exists != null) { var otherRequests = db.GetStockRequests(null, client, project, fromDate, toDate, "Approved", page, count).ToList(); for (int i = 0; i < otherRequests.Count(); i++) { stockRequests.Add(otherRequests[i]); } } if (stockRequests.Count() > 0) { TotalCount = stockRequests.FirstOrDefault().TotalCount; } return(Content(HttpStatusCode.OK, new { stockRequests, TotalCount })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetOrganisation(int orgId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var org = db.Organisations.Find(orgId); OrganisationModel organisation = new OrganisationModel(); organisation.Id = org.Id; organisation.OrgName = org.OrgName; organisation.Email = org.Email; organisation.PrimaryPhone = org.PrimaryPhone; organisation.Website = org.WebSite; organisation.SecondaryPhone = org.SecondaryPhone; organisation.PAN = org.PAN; organisation.TIN = org.TIN; organisation.GST = org.GST; organisation.EmpPrefix = org.EmpPrefix; organisation.OrgLogo = org.Logo; organisation.OrgLocation = new List <OrganisationLocation>(); var OrgLocations = db.OrgansationLocations.Where(x => x.OrgId == orgId).ToList(); for (int i = 0; i < OrgLocations.Count(); i++) { OrganisationLocation orgLoc = new OrganisationLocation(); orgLoc.LocId = OrgLocations[i].Id; orgLoc.AddressLine1 = OrgLocations[i].AddressLine1; orgLoc.AddressLine2 = OrgLocations[i].AddressLine2; orgLoc.City = OrgLocations[i].CityId; orgLoc.CityName = OrgLocations[i].City.Name; orgLoc.State = OrgLocations[i].StateId; orgLoc.StateName = OrgLocations[i].City.State.Name; orgLoc.Country = OrgLocations[i].CountryId; orgLoc.CountryName = OrgLocations[i].City.State.Country.Name; orgLoc.ZIP = OrgLocations[i].ZIP; organisation.OrgLocation.Add(orgLoc); } return(Content(HttpStatusCode.OK, new { organisation })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetLeadDetails(int leadId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var leadFullDetails = db.GetLeadDetail(leadId).ToList(); var leadDetails = leadFullDetails.GroupBy(x => x.OppId).Select(x => x.First()).Select(x => new { x.OppId, x.OpportunityName, x.OppTaskOwner, OppStatus = x.OppCurrentStatus, x.CreatedDate, x.Client, x.LeadLocation, x.Description, TaskOwner = x.OppTaskOwner, CompletedDate = x.ActualCompletedDate, x.CreatedBy, oppLog = leadFullDetails.Where(y => y.OppId == x.OppId).GroupBy(y => y.OppLogId).Select(y => y.First()).Select(y => new { oppLogId = y.OppLogId, OppLogCreatedBy = y.OppLogAssignedBy, y.OppLogAssignedTo, y.OppLogComments, LogDate = y.OppLogDate, LogStatus = y.OppLogStatus, Attachments = leadFullDetails.Where(a => a.OppLogIdForAttachment == y.OppLogId).GroupBy(a => a.AttachmentId).Select(a => a.First()).Select(a => new { a.AttachmentId, a.FileAttachment }).ToList() }).ToList(), clientContacts = leadFullDetails.Where(z => z.OppId == x.OppId).GroupBy(z => z.ClientEmpId).Select(z => z.First()).Select(z => new { FirstName = z.ClientEmpFirstName, LastName = z.ClientEmpLastName, Email = z.ClientEmpEmail, PhoneNumber = z.ClientEmpPhoneNumber, Department = z.clientEmpDepartment }).ToList() }).FirstOrDefault(); return(Content(HttpStatusCode.OK, new { leadDetails })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.StackTrace, ex.ToString()); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult AddDocument() { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; var docDate = form.Get("DocDate"); var files = HttpContext.Current.Request.Files; var Document = files["Documents"]; var fileExtension = Path.GetExtension(Document.FileName); var validExtensions = new string[] { ".jpg", ".jpeg", ".png", ".gif", ".doc", ".docx", ".pdf", ".txt", ".xls", ".xlsx" }; if (!validExtensions.Contains(fileExtension)) { return(Content(HttpStatusCode.InternalServerError, "Invalid file type for detailed estimate!!")); } Document doc = new Document(); if (!string.IsNullOrEmpty(docDate)) { doc.DocumentDate = DateTime.Parse(docDate); } doc.Category = form.Get("Category"); doc.Notes = form.Get("Notes"); doc.Keywords = form.Get("KeyWords"); doc.UploadDate = DateTime.Now; doc.Employee_Id = Convert.ToInt32(form.Get("EmployeeId")); var fileDirecory = HttpContext.Current.Server.MapPath("~/Employees/Document"); if (!Directory.Exists(fileDirecory)) { Directory.CreateDirectory(fileDirecory); } var fileName = DateTime.Now.Ticks + "_" + Document.FileName; var filepath = Path.Combine(fileDirecory, fileName); Document.SaveAs(filepath); doc.DocumentURL = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "Employee", "Documents", fileName); db.Documents.Add(doc); db.SaveChanges(); } return(Ok()); } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }
public IHttpActionResult GetEmployeesForTaskAllocation(string creatorId, int?orgId) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var LoginUser = User.Identity.GetUserId(); var user = db.Employees.Where(x => x.AspNetUserId == LoginUser && x.Active == true).Select(x => x.AspNetUserId).FirstOrDefault(); var superAdiminsList = db.Employees.Where(x => x.AspNetUserId != user && x.OrgId != orgId && x.Active == true && x.Role_Id == "8").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName + "(" + x.Organisation.OrgName + ")" }).OrderBy(x => x.label).ToList(); if (creatorId == null) { if (orgId != null) { var employeesOfOrg = db.Employees.Where(x => x.AspNetUserId != user && x.OrgId == orgId && x.Active == true && x.Role_Id != "4").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName }).OrderBy(x => x.label).ToList(); var employees = employeesOfOrg.Union(superAdiminsList).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } else { var employees = db.Employees.Where(x => x.AspNetUserId != user && x.Active == true && x.Role_Id != "4").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName + "(" + x.Organisation.OrgName + ")" }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } } else { var empList = db.Employees.Where(x => x.AspNetUserId != user).ToList(); if (orgId != null) { // var orgEmployeesList = empList.Where(x => x.AspNetUserId != creatorId && x.OrgId == orgId && x.Active == true && x.Role_Id != "4").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName }).OrderBy(x => x.label).ToList(); var orgEmployeesList = db.Employees.Where(x => x.AspNetUserId != creatorId && x.OrgId == orgId && x.Active == true && x.Role_Id != "4").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName }).OrderBy(x => x.label).ToList(); var employees = orgEmployeesList.Union(superAdiminsList).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } else { var employees = db.Employees.Where(x => x.AspNetUserId != user && x.AspNetUserId != creatorId && x.Active == true && x.Role_Id != "4").Select(x => new { value = x.AspNetUserId, label = x.FirstName + " " + x.LastName + "(" + x.Organisation.OrgName + ")" }).OrderBy(x => x.label).ToList(); return(Content(HttpStatusCode.OK, new { employees })); } } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured please try again llater")); } }
public IHttpActionResult GetUploadedFiles(string userName, DateTime?fromDate, DateTime?toDate, int?doctorId, string jobNumber, string status, int page, int count, string sortCol, string sortDir) { try { using (MaxMasterDbEntities dbMaster = new MaxMasterDbEntities()) { var user = dbMaster.AspNetUsers.Where(x => x.Email == userName).FirstOrDefault(); var userId = user.Id; var clientId = dbMaster.ClientEmployees.Where(x => x.Email == userName).Select(x => x.Client_Id).FirstOrDefault(); var doctors = dbMaster.Doctors.Where(x => x.Client_Id == clientId).Select(x => new { value = x.Id, label = x.FirstName + " " + x.LastName }).OrderBy(x => x.label).ToList(); using (MaxMRSEntities db = new MaxMRSEntities()) { int totalcount = 0; var EmployeeUploads = db.GetClientUploadedJobs(userName, fromDate, toDate, doctorId, jobNumber, status, page, count, sortCol, sortDir).ToList(); if (EmployeeUploads.Count > 0) { totalcount = (int)EmployeeUploads.FirstOrDefault().TotalCount; } UploadsModel uploads = new UploadsModel(); List <UploadsModel> clientUploadsList = new List <UploadsModel>(); foreach (var uplds in EmployeeUploads) { string[] filesplit = uplds.ClientFilePath.Split('/'); string fName = filesplit.Last(); clientUploadsList.Add(new UploadsModel() { DoctorName = uplds.DoctorName, ClientFilePath = uplds.ClientFilePath, Status = uplds.Status, FileName = fName, JobNumber = uplds.JobNumber, UploadedDate = uplds.Arrival_Time, TotalPages = uplds.TotalPages }); } return(Content(HttpStatusCode.OK, new { doctors, totalcount, clientUploadsList })); } } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.OK, "An error occured, please try agin later")); } }
public IHttpActionResult GetBilledModelInfo(int modelId, string billNumber, string supplier) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var itemDetails = db.Items.Where(x => x.ItemModelId == modelId && x.BillNumber == billNumber && x.SupplierId == supplier).ToList(); ItemModel itemInfo = new ItemModel(); if (itemDetails.Count() > 0) { itemInfo.BatchNo = itemDetails[0].BatchNumber; itemInfo.HardwareVersion = itemDetails[0].HardwareVersion; itemInfo.StockLocation = itemDetails[0].StockLocationId; itemInfo.CP = itemDetails[0].CostPrice; itemInfo.MinSP = itemDetails[0].MinimumSP; itemInfo.SP = itemDetails[0].SellingPrice; itemInfo.MRP = itemDetails[0].MRP; itemInfo.Warrenty = itemDetails[0].Warrenty; itemInfo.WarrentyPeriod = itemDetails[0].WarrentyPeriod; itemInfo.StockInDate = itemDetails[0].StockInDate; itemInfo.Units = itemDetails[0].ItemsMaster.Units; // itemInfo.SerialNumExists = itemDetails[0].ItemsMaster.SrlNoExists; var loc = db.OrgansationLocations.Where(x => x.Id == itemInfo.StockLocation).FirstOrDefault(); itemInfo.Location = loc.AddressLine1 + ", " + loc.AddressLine2 + loc.City.Name + ", " + loc.City.State.Name + "," + loc.City.State.Country.Name + "," + loc.ZIP; List <ItemDetails> items = new List <ItemDetails>(); for (int i = 0; i < itemDetails.Count(); i++) { ItemDetails item = new ItemDetails(); item.Id = itemDetails[i].Id; item.SerialNumber = itemDetails[i].SerialNumber; item.MacAddress = itemDetails[i].MACAddress; item.ManufacturedDate = itemDetails[i].ManufacturedDate; items.Add(item); } itemInfo.Items = items; } return(Content(HttpStatusCode.OK, new { itemInfo, Result = itemDetails != null })); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An errror occured, please try agian later")); } }
public IHttpActionResult UpdateItemModel(int id) { try { using (MaxMasterDbEntities db = new MaxMasterDbEntities()) { var form = HttpContext.Current.Request.Form; ItemsMaster im = db.ItemsMasters.Find(id); im.Brand = form.Get("Brand"); im.ModelNumber = form.Get("ModelNumber"); im.ItemName = form.Get("ItemName"); im.HSNCode = form.Get("HsnCode"); im.UPC = form.Get("Upc"); im.EAN = form.Get("Ean"); im.Description = form.Get("Description"); im.ItemContents = form.Get("Contents"); im.MadeIn = Convert.ToInt32(form.Get("Country")); im.Manufacturer = form.Get("Manufacturer"); // im.PowerInput = Convert.ToInt32(form.Get("PowerInput")); int?powerUnit = im.PowerInput; if (form.Get("PowerInput") != "") { im.PowerInput = Convert.ToInt32(form.Get("PowerInput")); im.PowerInputUnits = form.Get("PowerUnits"); } else { im.PowerInput = null; im.PowerInputUnits = null; } im.ThresholdQuantity = Convert.ToInt32(form.Get("ThresholdValue")); im.UpdatedBy = User.Identity.GetUserId(); im.LastUpdated = MasterDataController.GetIndianTime(DateTime.Now); im.Units = form.Get("Units"); im.GST = Convert.ToDecimal(form.Get("Gst")) / 2; im.CGST = Convert.ToDecimal(form.Get("Gst")) / 2; im.SrlNoExists = Convert.ToBoolean(form.Get("SrlNoExits")); db.Entry(im).State = EntityState.Modified; db.SaveChanges(); return(Ok()); } } catch (Exception ex) { new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace); return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later")); } }