public JsonResult Save(MstCustomer content)
        {
            var repos  = new Repository.MstCustomer();
            var result = repos.Save(content);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public static bool Update(CustomerViewModel model)
        {
            bool result = true;

            try
            {
                using (var db = new FleetManagementContext())
                {
                    if (model.Id == 0)
                    {
                        MstCustomer ctm = new MstCustomer();
                        ctm.CustomerId          = model.CustomerId;
                        ctm.CustomerName        = model.CustomerName;
                        ctm.OrganizationName    = model.OrganizationName;
                        ctm.CustomerAddress     = model.CustomerAddress;
                        ctm.OrganizationAddress = model.OrganizationAddress;
                        ctm.IdNumber            = model.IdNumber;
                        ctm.CustomerPhone       = model.CustomerPhone;
                        ctm.OrganizationPhone   = model.OrganizationPhone;
                        ctm.OrganizationEmail   = model.OrganizationEmail;
                        ctm.IsActive            = model.IsActive;
                        db.MstCustomers.Add(ctm);
                        db.SaveChanges();
                    }
                    else
                    {
                        MstCustomer ctm = db.MstCustomers.Where(o => o.Id == model.Id).FirstOrDefault();
                        if (ctm != null)
                        {
                            ctm.CustomerId          = model.CustomerId;
                            ctm.CustomerName        = model.CustomerName;
                            ctm.OrganizationName    = model.OrganizationName;
                            ctm.CustomerAddress     = model.CustomerAddress;
                            ctm.OrganizationAddress = model.OrganizationAddress;
                            ctm.IdNumber            = model.IdNumber;
                            ctm.CustomerPhone       = model.CustomerPhone;
                            ctm.OrganizationPhone   = model.OrganizationPhone;
                            ctm.OrganizationEmail   = model.OrganizationEmail;
                            ctm.IsActive            = model.IsActive;
                            db.SaveChanges();
                        }
                    }
                }
            }
            catch (Exception Ex)
            {
                Message = Ex.Message;
                result  = false;
            }

            return(result);
        }
Beispiel #3
0
        public HttpResponseMessage UnLockMstCustomer(MstCustomer customer)
        {
            try
            {
                var MstCustomerData = from d in db.MstCustomers
                                      where d.Id == Convert.ToInt32(customer.Id)
                                      select d;

                if (MstCustomerData.Any())
                {
                    var currentUser = from d in db.MstUsers
                                      where d.AspNetId == User.Identity.GetUserId()
                                      select d;

                    if (currentUser.Any())
                    {
                        var UnLockCustomerData = MstCustomerData.FirstOrDefault();

                        UnLockCustomerData.IsLocked        = false;
                        UnLockCustomerData.UpdatedBy       = currentUser.FirstOrDefault().Id;
                        UnLockCustomerData.UpdatedDateTime = DateTime.Now;

                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Beispiel #4
0
        public static bool Delete(int id)
        {
            bool result = true;

            try
            {
                using (var db = new FleetManagementContext())
                {
                    MstCustomer ctm = db.MstCustomers.Where(o => o.Id == id).FirstOrDefault();
                    if (ctm != null)
                    {
                        db.MstCustomers.Remove(ctm);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception Ex)
            {
                Message = Ex.Message;
                result  = false;
            }
            return(result);
        }
Beispiel #5
0
        public HttpResponseMessage LockMstCustomer(MstCustomer customer)
        {
            try
            {
                var MstCustomerData = from d in db.MstCustomers
                                      where d.Id == Convert.ToInt32(customer.Id)
                                      select d;

                if (MstCustomerData.Any())
                {
                    var currentUser = from d in db.MstUsers
                                      where d.AspNetId == User.Identity.GetUserId()
                                      select d;

                    if (currentUser.Any())
                    {
                        var UpdateCustomerData = MstCustomerData.FirstOrDefault();

                        UpdateCustomerData.CustomerCode            = customer.CustomerCode;
                        UpdateCustomerData.LastName                = customer.LastName;
                        UpdateCustomerData.FirstName               = customer.FirstName;
                        UpdateCustomerData.MiddleName              = customer.MiddleName;
                        UpdateCustomerData.CivilStatus             = customer.CivilStatus;
                        UpdateCustomerData.Gender                  = customer.Gender;
                        UpdateCustomerData.BirthDate               = Convert.ToDateTime(customer.BirthDate);
                        UpdateCustomerData.Citizen                 = customer.Citizen;
                        UpdateCustomerData.TIN                     = customer.TIN;
                        UpdateCustomerData.IdType                  = customer.IdType;
                        UpdateCustomerData.IdNumber                = customer.IdNumber;
                        UpdateCustomerData.Address                 = customer.Address;
                        UpdateCustomerData.City                    = customer.City;
                        UpdateCustomerData.Province                = customer.Province;
                        UpdateCustomerData.Country                 = customer.Country;
                        UpdateCustomerData.ZipCode                 = customer.ZipCode;
                        UpdateCustomerData.EmailAddress            = customer.EmailAddress;
                        UpdateCustomerData.TelephoneNumber         = customer.TelephoneNumber;
                        UpdateCustomerData.MobileNumber            = customer.MobileNumber;
                        UpdateCustomerData.Employer                = customer.Employer;
                        UpdateCustomerData.EmployerIndustry        = customer.EmployerIndustry;
                        UpdateCustomerData.NoOfYearsEmployed       = customer.NoOfYearsEmployed;
                        UpdateCustomerData.Position                = customer.Position;
                        UpdateCustomerData.EmploymentStatus        = customer.EmploymentStatus;
                        UpdateCustomerData.EmployerAddress         = customer.EmployerAddress;
                        UpdateCustomerData.EmployerCity            = customer.EmployerCity;
                        UpdateCustomerData.EmployerProvince        = customer.EmployerProvince;
                        UpdateCustomerData.EmployerCountry         = customer.EmployerCountry;
                        UpdateCustomerData.EmployerZipCode         = customer.EmployerZipCode;
                        UpdateCustomerData.EmployerTelephoneNumber = customer.EmployerTelephoneNumber;
                        UpdateCustomerData.EmployerMobileNumber    = customer.EmployerMobileNumber;
                        UpdateCustomerData.Picture                 = customer.Picture;
                        UpdateCustomerData.Attachment1             = customer.Attachment1;
                        UpdateCustomerData.Attachment2             = customer.Attachment2;
                        UpdateCustomerData.Attachment3             = customer.Attachment3;
                        UpdateCustomerData.Attachment4             = customer.Attachment4;
                        UpdateCustomerData.Attachment5             = customer.Attachment5;
                        UpdateCustomerData.SpouseLastName          = customer.SpouseLastName;
                        UpdateCustomerData.SpouseFirstName         = customer.SpouseFirstName;
                        UpdateCustomerData.SpouseMiddleName        = customer.SpouseMiddleName;
                        UpdateCustomerData.SpouseBirthDate         = Convert.ToDateTime(customer.SpouseBirthDate);
                        UpdateCustomerData.SpouseCitizen           = customer.SpouseCitizen;
                        UpdateCustomerData.SpouseEmployer          = customer.SpouseEmployer;
                        UpdateCustomerData.SpouseTIN               = customer.SpouseTIN;
                        UpdateCustomerData.Remarks                 = customer.Remarks;
                        UpdateCustomerData.Status                  = customer.Status;
                        UpdateCustomerData.IsLocked                = true;
                        UpdateCustomerData.UpdatedBy               = currentUser.FirstOrDefault().Id;
                        UpdateCustomerData.UpdatedDateTime         = DateTime.Now;
                        UpdateCustomerData.BusinessName            = customer.BusinessName;
                        UpdateCustomerData.BusinessAddress         = customer.BusinessAddress;
                        UpdateCustomerData.BusinessType            = customer.BusinessType;
                        UpdateCustomerData.BusinessPosition        = customer.BusinessPosition;

                        db.SubmitChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.BadRequest));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Beispiel #6
0
        public Int32 PostMstCustomer(MstCustomer customer)
        {
            try
            {
                var currentUser = from d in db.MstUsers
                                  where d.AspNetId == User.Identity.GetUserId()
                                  select d;

                if (currentUser.Any())
                {
                    string customerCode = "0001";
                    var    customers    = from d in db.MstCustomers.OrderByDescending(d => d.Id) select d;
                    if (customers.Any())
                    {
                        Int32 nextCustomerCode = Convert.ToInt32(customers.FirstOrDefault().CustomerCode) + 1;
                        customerCode = padNumWithZero(nextCustomerCode, 4);
                    }

                    Data.MstCustomer newMstCustomer = new Data.MstCustomer()
                    {
                        CustomerCode            = customerCode,
                        LastName                = customer.LastName,
                        FirstName               = customer.FirstName,
                        MiddleName              = customer.MiddleName,
                        CivilStatus             = customer.CivilStatus,
                        Gender                  = customer.Gender,
                        BirthDate               = Convert.ToDateTime(customer.BirthDate),
                        Citizen                 = customer.Citizen,
                        TIN                     = customer.TIN,
                        IdType                  = customer.IdType,
                        IdNumber                = customer.IdNumber,
                        Address                 = customer.Address,
                        City                    = customer.City,
                        Province                = customer.Province,
                        Country                 = customer.Country,
                        ZipCode                 = customer.ZipCode,
                        EmailAddress            = customer.EmailAddress,
                        TelephoneNumber         = customer.TelephoneNumber,
                        MobileNumber            = customer.MobileNumber,
                        Employer                = customer.Employer,
                        EmployerIndustry        = customer.EmployerIndustry,
                        NoOfYearsEmployed       = customer.NoOfYearsEmployed,
                        Position                = customer.Position,
                        EmploymentStatus        = customer.EmploymentStatus,
                        EmployerAddress         = customer.EmployerAddress,
                        EmployerCity            = customer.EmployerCity,
                        EmployerProvince        = customer.EmployerProvince,
                        EmployerCountry         = customer.EmployerCountry,
                        EmployerZipCode         = customer.EmployerZipCode,
                        EmployerTelephoneNumber = customer.EmployerTelephoneNumber,
                        EmployerMobileNumber    = customer.EmployerMobileNumber,
                        SpouseLastName          = customer.SpouseLastName,
                        SpouseFirstName         = customer.SpouseFirstName,
                        SpouseMiddleName        = customer.SpouseMiddleName,
                        SpouseBirthDate         = Convert.ToDateTime(customer.SpouseBirthDate),
                        SpouseCitizen           = customer.SpouseCitizen,
                        SpouseEmployer          = customer.SpouseEmployer,
                        SpouseTIN               = customer.SpouseTIN,
                        Remarks                 = customer.Remarks,
                        Status                  = customer.Status,
                        Picture                 = customer.Picture,
                        Attachment1             = customer.Attachment1,
                        Attachment2             = customer.Attachment2,
                        Attachment3             = customer.Attachment3,
                        Attachment4             = customer.Attachment4,
                        Attachment5             = customer.Attachment5,
                        IsLocked                = customer.IsLocked,
                        CreatedBy               = currentUser.FirstOrDefault().Id,
                        CreatedDateTime         = DateTime.Now,
                        UpdatedBy               = currentUser.FirstOrDefault().Id,
                        UpdatedDateTime         = DateTime.Now,
                        BusinessName            = customer.BusinessName,
                        BusinessAddress         = customer.BusinessAddress,
                        BusinessType            = customer.BusinessType,
                        BusinessPosition        = customer.BusinessPosition
                    };

                    db.MstCustomers.InsertOnSubmit(newMstCustomer);
                    db.SubmitChanges();

                    return(newMstCustomer.Id);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(0);
            }
        }