Exemple #1
0
        public async Task <IHttpActionResult> UpdateClient()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form            = HttpContext.Current.Request.Form;
                    var id              = form.Get("ClientId");
                    var clientLocations = JsonConvert.DeserializeObject <List <ClientLocationModel> >(form.Get("ClientLocations"));
                    var verticals       = JsonConvert.DeserializeObject <List <ClientVerticalsModel> >(form.Get("ClientVerticals"));
                    var oldMail         = form.Get("OldEmail");
                    var email           = form.Get("Email");
                    var count           = 0;
                    var currency        = form.Get("Currency");
                    var paymentType     = form.Get("PaymentType");
                    var paymentAmount   = form.Get("PaymentAmount");
                    var gst             = form.Get("gst");
                    var pan             = form.Get("pan");
                    var creditPeriod    = form.Get("creditPeriod");

                    //locationId

                    Client client = db.Clients.Find(Convert.ToInt32(id));

                    if (oldMail.ToLower() != email.ToLower())
                    {
                        var userName = _userManager.FindByEmail(oldMail);
                        var userId   = userName.Id;

                        var exists = _userManager.FindByEmailAsync(email);
                        if (exists != null)
                        {
                            //   return Content(HttpStatusCode.InternalServerError, "User with email " + email + "already exists");
                        }

                        var res = await _userManager.SetEmailAsync(userId, email);
                    }

                    if (client == null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Invalid Data"));
                    }

                    var clientVerticalList = client.ClientVerticals.ToList();

                    if (clientVerticalList.Count > 0)
                    {
                        foreach (var vertical in client.ClientVerticals.ToList())
                        {
                            client.ClientVerticals.Remove(vertical);
                        }
                    }

                    client.Name           = form.Get("Name");
                    client.ShortName      = form.Get("ShortName");
                    client.Email          = form.Get("Email");
                    client.PrimaryPhone   = form.Get("PrimaryPhone");
                    client.SecondaryPhone = form.Get("SecondaryPhone");
                    client.Fax            = form.Get("Fax");
                    client.ClientType     = form.Get("ClientType");
                    client.Active         = Convert.ToBoolean(form.Get("IsActive"));
                    client.OrgId          = Convert.ToInt32(form.Get("Organisation"));
                    client.ClientStatus   = form.Get("ClientStatus");

                    for (int i = 0; i < verticals.Count(); i++)
                    {
                        var clientVertical = await db.ClientVerticals.FindAsync(verticals[i].value);

                        client.ClientVerticals.Add(clientVertical);
                    }

                    for (int i = 0; i < clientLocations.Count; i++)
                    {
                        var loc = clientLocations[i].LocationId;

                        if (loc != null)
                        {
                            var clientLoc = db.ClientLocations.Find(clientLocations[i].LocationId);
                            clientLoc.AddressLine1     = clientLocations[i].AddressLine1;
                            clientLoc.AddressLine2     = clientLocations[i].AddressLine2;
                            clientLoc.Landmark         = clientLocations[i].Landmark;
                            clientLoc.Country_Id       = clientLocations[i].Country;
                            clientLoc.State_Id         = clientLocations[i].State;
                            clientLoc.City_Id          = clientLocations[i].City;
                            clientLoc.ZIP              = clientLocations[i].zip;
                            clientLoc.TimeZone_Id      = clientLocations[i].TimeZone;
                            clientLoc.IsInvoiceAddress = clientLocations[i].IsInvoice;

                            //if (clientLoc.Country_Id == 101)
                            //{
                            //    count++;
                            //}

                            db.Entry(clientLoc).State = System.Data.Entity.EntityState.Modified;
                        }
                        else
                        {
                            ClientLocation clientloc = new ClientLocation();
                            clientloc.AddressLine1     = clientLocations[i].AddressLine1;
                            clientloc.AddressLine2     = clientLocations[i].AddressLine2;
                            clientloc.Landmark         = clientLocations[i].Landmark;
                            clientloc.Country_Id       = clientLocations[i].Country;
                            clientloc.State_Id         = clientLocations[i].State;
                            clientloc.City_Id          = clientLocations[i].City;
                            clientloc.ZIP              = clientLocations[i].zip;
                            clientloc.TimeZone_Id      = clientLocations[i].TimeZone;
                            clientloc.IsInvoiceAddress = clientLocations[i].IsInvoice;
                            client.ClientLocations.Add(clientloc);
                            db.SaveChanges();
                        }
                    }

                    if (form.Get("ClientType") == "Supplier")
                    {
                        client.AccountName   = form.Get("accountName");
                        client.AccountNumber = form.Get("accountNumber");
                        client.BankName      = form.Get("bankName");
                        client.BranchName    = form.Get("branchName");
                        client.IFSCCode      = form.Get("ifscCode");
                    }

                    if (gst != null)
                    {
                        client.GST = gst;
                    }

                    else
                    {
                        client.GST = null;
                    }

                    if (pan != null)
                    {
                        client.PAN = pan;
                    }
                    if (creditPeriod != "")
                    {
                        client.CreditPeriod = Convert.ToInt32(form.Get("creditPeriod"));
                    }

                    else
                    {
                        client.GST          = null;
                        client.PAN          = null;
                        client.CreditPeriod = null;
                    }

                    if (client.ClientType != "Supplier" && client.ClientType != "Vendor")
                    {
                        if (paymentType != null)
                        {
                            client.PaymentType = form.Get("PaymentType");
                        }
                        else
                        {
                            client.PaymentType = null;
                        }

                        var Amount = (form.Get("PaymentAmount"));
                        if (Amount != "")
                        {
                            client.PaymentAmount = Convert.ToDecimal(form.Get("PaymentAmount"));
                        }
                        else
                        {
                            client.PaymentAmount = null;
                        }

                        if (currency != null)
                        {
                            client.Currency = form.Get("Currency");
                        }
                        else
                        {
                            client.Currency = null;
                        }
                    }
                    else
                    {
                        client.PaymentType   = null;
                        client.Currency      = null;
                        client.PaymentAmount = null;
                    }

                    db.Entry(client).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 IHttpActionResult EditActivity()
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var form           = HttpContext.Current.Request.Form;
                    var taskId         = form.Get("taskId");
                    var userId         = User.Identity.GetUserId();
                    var hoursWorked    = form.Get("hoursWorked");
                    var quantityWorked = form.Get("quantityWorked");
                    int orgId          = Convert.ToInt32(form.Get("OrgId"));
                    var actionType     = form.Get("actionType");

                    var activityNotification = db.AddActivityNotifications(taskId, User.Identity.GetUserId());

                    Activity mainTask = db.Activities.Find(taskId);

                    if (actionType == "Assign")
                    {
                        var assigneeList = JsonConvert.DeserializeObject <List <Assignee> >(form.Get("assigneeList"));

                        if (assigneeList.Count() > 1)
                        {
                            foreach (var assignee in assigneeList)
                            {
                                var  parentTaskLog     = JsonConvert.DeserializeObject <List <ActivityLog> >(form.Get("ParentTaskDetails"));
                                bool CreateNewActivity = AddChildTask(mainTask, assignee, parentTaskLog);
                                if (!CreateNewActivity)
                                {
                                    return(Content(HttpStatusCode.InternalServerError, "Faied to assignee task"));
                                }
                            }
                        }
                        else
                        {
                            if (mainTask.ParentTask_Id != null)
                            {
                                ActivitiesLog parentLog = new ActivitiesLog();

                                parentLog.TaskId     = mainTask.ParentTask_Id;
                                parentLog.TaskDate   = MasterDataController.GetIndianTime(DateTime.Now);
                                parentLog.AssignedBy = User.Identity.GetUserId();
                                parentLog.AssignedTo = assigneeList[0].AssigneeId;
                                parentLog.Status     = "Open";
                                if (hoursWorked != "" && hoursWorked != "NaN")
                                {
                                    parentLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                                }
                                parentLog.Description = form.Get("description");
                                if (quantityWorked != "" && quantityWorked != "NaN")
                                {
                                    parentLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                                }

                                db.ActivitiesLogs.Add(parentLog);
                            }

                            mainTask.Status        = "Open";
                            mainTask.TaskOwner     = assigneeList[0].AssigneeId;
                            mainTask.LastUpdatedBy = User.Identity.GetUserId();
                            mainTask.LastUpdated   = MasterDataController.GetIndianTime(DateTime.Now);
                        }
                    }

                    else
                    {
                        var      childTasks = db.Activities.Where(x => x.ParentTask_Id == mainTask.TaskId).ToList();
                        Activity parentTask = db.Activities.Where(x => x.TaskId == mainTask.ParentTask_Id).FirstOrDefault();

                        ActivitiesLog activityLog = new ActivitiesLog();

                        if (childTasks.Count > 0)
                        {
                            foreach (var child in childTasks)
                            {
                                ActivitiesLog childLog = new ActivitiesLog();

                                childLog.TaskId        = child.TaskId;
                                childLog.AssignedBy    = User.Identity.GetUserId();
                                childLog.TaskDate      = MasterDataController.GetIndianTime(DateTime.Now);
                                childLog.Description   = form.Get("description");
                                childLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));

                                db.ActivitiesLogs.Add(childLog);
                            }
                        }

                        if (actionType == "InProcess")
                        {
                            activityLog.AssignedTo = User.Identity.GetUserId();
                            activityLog.StartDate  = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edos")));
                            activityLog.EndDate    = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edoc")));
                            activityLog.Status     = "InProcess";

                            mainTask.Status = "InProcess";
                        }
                        else if (actionType == "Pending")
                        {
                            activityLog.AssignedTo = User.Identity.GetUserId();
                            activityLog.StartDate  = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edos")));
                            activityLog.EndDate    = MasterDataController.GetIndianTime(Convert.ToDateTime(form.Get("edoc")));
                            activityLog.Status     = "Pending";

                            mainTask.Status = "Pending";
                        }
                        else if (actionType == "Resolved")
                        {
                            activityLog.AssignedTo = mainTask.CreatedBy;
                            activityLog.AssignedBy = User.Identity.GetUserId();
                            activityLog.Status     = "Resolved";

                            mainTask.TaskOwner = mainTask.CreatedBy;
                            mainTask.Status    = "Resolved";
                        }
                        else if (actionType == "AcceptToClose")
                        {
                            activityLog.Status     = "Closed by assignee";
                            activityLog.AssignedBy = mainTask.TaskOwner;
                            activityLog.AssignedTo = mainTask.CreatedBy;

                            mainTask.TaskOwner = mainTask.CreatedBy;
                            mainTask.Status    = "Closed";
                        }
                        else if (actionType == "Comments")
                        {
                            activityLog.AssignedTo = mainTask.TaskOwner;
                            activityLog.AssignedBy = User.Identity.GetUserId();

                            mainTask.Status = mainTask.Status;
                        }
                        else
                        {
                            if (actionType == "Reopen")
                            {
                                activityLog.AssignedTo = mainTask.LastUpdatedBy;
                                activityLog.AssignedBy = User.Identity.GetUserId();
                                activityLog.Status     = "Reopened";

                                mainTask.Status = "Reopened";
                            }
                        }

                        if (parentTask != null)
                        {
                            ActivitiesLog parentLog = new ActivitiesLog();

                            parentLog.TaskId     = parentTask.ParentTask_Id;
                            parentLog.TaskDate   = MasterDataController.GetIndianTime(DateTime.Now);
                            parentLog.AssignedBy = User.Identity.GetUserId();
                            parentLog.AssignedTo = parentTask.TaskOwner;

                            if (actionType == "Pending" || actionType == "Comments")
                            {
                                parentLog.Status = "Pending";
                            }
                            else if (actionType == "InProcess")
                            {
                                parentLog.Status = "InProcess";
                            }
                            else if (actionType == "Assign")
                            {
                                parentLog.Status = "Open";
                            }
                            else if (actionType == "Reopen")
                            {
                                parentLog.Status = "Reopened";
                            }
                            else if (actionType == "AcceptToClose")
                            {
                                var childTasksList = db.Activities.Where(x => x.ParentTask_Id == mainTask.TaskId).ToList();
                            }
                            else if (actionType == "Resolved")
                            {
                            }
                            else
                            {
                                parentLog.Status = "";
                            }

                            parentLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));
                            if (hoursWorked != "" && hoursWorked != "NaN")
                            {
                                parentLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                            }
                            parentLog.Description = form.Get("description");
                            if (quantityWorked != "" && quantityWorked != "NaN")
                            {
                                parentLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                            }
                            db.ActivitiesLogs.Add(parentLog);
                        }

                        activityLog.AssignedBy    = User.Identity.GetUserId();
                        activityLog.TaskDate      = MasterDataController.GetIndianTime(DateTime.Now);
                        activityLog.Description   = form.Get("description");
                        activityLog.BudgetedHours = Convert.ToInt32(form.Get("budgetedHours"));
                        if (hoursWorked != "" && hoursWorked != "NaN")
                        {
                            activityLog.HoursWorked = Convert.ToInt32(form.Get("hoursWorked"));
                        }

                        if (quantityWorked != "" && quantityWorked != "NaN")
                        {
                            activityLog.QuantityWorked = Convert.ToInt32(form.Get("quantityWorked"));
                        }
                        mainTask.ActivitiesLogs.Add(activityLog);

                        mainTask.LastUpdatedBy = User.Identity.GetUserId();
                        mainTask.LastUpdated   = MasterDataController.GetIndianTime(DateTime.Now);

                        db.Entry(mainTask).State = System.Data.Entity.EntityState.Modified;
                    }
                }

                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"));
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> UpdateClientEmployee(int EmployeeId)
        {
            try
            {
                var form     = HttpContext.Current.Request.Form;
                var id       = form.Get("Id");
                var clientId = form.Get("ClientId");
                var oldMail  = form.Get("OldEmail");
                var email    = form.Get("Email");


                if (oldMail.ToLower() != email.ToLower())
                {
                    var userName = _userManager.FindByEmail(oldMail);
                    var userId   = userName.Id;

                    var exists = _userManager.FindByEmailAsync(email);
                    if (exists != null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "User with email " + email + "already exists"));
                    }

                    var res = await _userManager.SetEmailAsync(userId, email);
                }

                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    ClientEmployee clEmp = db.ClientEmployees.Find(Convert.ToInt32(id));

                    if (clEmp == null)
                    {
                        return(Content(HttpStatusCode.InternalServerError, "Invalid Data"));
                    }

                    clEmp.FirstName      = form.Get("FirstName").ToString();
                    clEmp.LastName       = form.Get("LastName").ToString();
                    clEmp.MiddleName     = form.Get("MiddleName").ToString();
                    clEmp.Email          = form.Get("Email");
                    clEmp.Fax            = form.Get("Fax").ToString();
                    clEmp.PrimaryPhone   = form.Get("PrimaryPhoneNum").ToString();
                    clEmp.SecondaryPhone = form.Get("SecondaryPhoneNum").ToString();
                    clEmp.LastUpdated    = DateTime.Now;
                    clEmp.Department     = form.Get("Department").ToString();
                    clEmp.Client_Id      = Convert.ToInt32(clientId);

                    //   clEmp.Active = true;

                    var files = HttpContext.Current.Request.Files;

                    if (files.Count > 0)
                    {
                        for (int i = 0; i < files.Count; i++)
                        {
                            if (files.GetKey(i).Contains("ImageOne"))
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");

                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clEmp.ImageOne = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }

                            else if (files.GetKey(i).Contains("ImageTwo"))
                            {
                                var fileDirectory = HttpContext.Current.Server.MapPath("~/ClientContactsImages");
                                if (!Directory.Exists(fileDirectory))
                                {
                                    Directory.CreateDirectory(fileDirectory);
                                }
                                var fileName = files[i].FileName;
                                var filePath = Path.Combine(fileDirectory, fileName);
                                files[i].SaveAs(filePath);
                                clEmp.ImageTwo = Path.Combine(ConfigurationManager.AppSettings["ApiUrl"], "ClientContactsImages", fileName);
                            }
                        }
                    }


                    db.Entry(clEmp).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 occoured, please try again!"));
            }
        }