Exemple #1
0
 public ActionResult Edit(UserProfile userprofile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userprofile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToRoute("Users"));
     }
     return(View(userprofile));
 }
        public ActionResult Create(Room room)
        {
            if (ModelState.IsValid)
            {
                db.Room.Add(room);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(room));
        }
        public ActionResult Create(EstimateForm estimateform)
        {
            if (ModelState.IsValid)
            {
                db.EstimateForm.Add(estimateform);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(estimateform));
        }
        public ActionResult Create(string inventoryitem)
        {
            var invItem = new InventoryItem();

            invItem.inventoryItem = inventoryitem;

            if (ModelState.IsValid)
            {
                db.InventoryItem.Add(invItem);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(inventoryitem));
        }
Exemple #5
0
 public ActionResult Index(Content content)
 {
     if (ModelState.IsValid)
     {
         db.Entry(content).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(content));
 }
Exemple #6
0
        public static void CreateCustomerEstimate(int estimateId)
        {
            var existing = db.CustomerEstimates.FirstOrDefault(x => x.EstimateId == estimateId);

            if (existing == null)
            {
                var model = new CustomerEstimates()
                {
                    EstimateId = estimateId
                };

                db.CustomerEstimates.Add(model);
                db.SaveChanges();
            }
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (OCMovers_MVC4Context db = new OCMovers_MVC4Context())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Exemple #8
0
        public ActionResult SaveCustomerEstimate(CreateCustomerEstimate estimate)
        {
            var existing = db.CustomerEstimates.FirstOrDefault(x => x.EstimateId == estimate.EstimateFormId);

            if (existing != null)
            {
                existing.CreateDate          = estimate.CreateDate;
                existing.Start               = estimate.Start;
                existing.End                 = estimate.End;
                existing.CustomerEstimatesId = existing.CustomerEstimatesId;
                existing.EstimateId          = estimate.EstimateFormId;
                existing.ArrivalText         = estimate.ArrivalText;
                existing.ArrivalTime         = estimate.ArrivalTime;
                existing.CancellationText    = estimate.CancellationText;
                existing.CustomerName        = estimate.CustomerName;
                existing.ElevatorText        = estimate.ElevatorText;
                existing.Fuel                = estimate.Fuel;
                existing.HourlyRateText      = estimate.HourlyRateText;
                existing.HoursEstimate       = estimate.HoursEstimate;
                existing.IntroText           = estimate.IntroText;
                existing.MattressCoverText   = estimate.MattressCoverText;
                existing.MoveDate            = estimate.MoveDate;
                existing.ParkingPermits      = estimate.ParkingPermits;
                existing.ParkingPermitsText  = estimate.ParkingPermitsText;
                existing.PaymentsText        = estimate.PaymentsText;
                existing.PhoneNumber         = estimate.PhoneNumber;
                existing.ReadPoliciesText    = estimate.ReadPoliciesText;
                existing.ResponsibleText     = estimate.ResponsibleText;
                existing.StormText           = estimate.StormText;
                existing.Tolls               = estimate.Tolls;
                existing.TotalEstimate       = estimate.TotalEstimate;
                existing.TravelTimeText      = estimate.TravelTimeText;
                existing.RepName             = estimate.RepName;

                db.Entry(existing).State = EntityState.Modified;
                db.SaveChanges();
            }

            var model = new CustomerEstimates()
            {
                CreateDate         = DateTime.Now,
                Start              = estimate.Start,
                End                = estimate.End,
                EstimateId         = estimate.EstimateFormId,
                ArrivalText        = estimate.ArrivalText,
                ArrivalTime        = estimate.ArrivalTime,
                CancellationText   = estimate.CancellationText,
                CustomerName       = estimate.CustomerName,
                ElevatorText       = estimate.ElevatorText,
                Fuel               = estimate.Fuel,
                HourlyRateText     = estimate.HourlyRateText,
                HoursEstimate      = estimate.HoursEstimate,
                IntroText          = estimate.IntroText,
                MattressCoverText  = estimate.MattressCoverText,
                MoveDate           = estimate.MoveDate,
                ParkingPermits     = estimate.ParkingPermits,
                ParkingPermitsText = estimate.ParkingPermitsText,
                PaymentsText       = estimate.PaymentsText,
                PhoneNumber        = estimate.PhoneNumber,
                ReadPoliciesText   = estimate.ReadPoliciesText,
                ResponsibleText    = estimate.ResponsibleText,
                StormText          = estimate.StormText,
                Tolls              = estimate.Tolls,
                TotalEstimate      = estimate.TotalEstimate,
                TravelTimeText     = estimate.TravelTimeText,
                RepName            = estimate.RepName
            };

            db.CustomerEstimates.Add(model);
            db.SaveChanges();

            return(RedirectToAction("ViewCustomerEstimate", new { id = model.CustomerEstimatesId }));
        }
        public JsonResult SendEstimate(OCMovers_MC4.ViewModel.EstimateForm estimateForm, List <Address> addresses, List <EstimateFormInventory> model = null)
        {
            Console.WriteLine(addresses);

            try
            {
                if (ModelState.IsValid)
                {
                    Guid EG = Guid.NewGuid();

                    estimateForm.EstimateGuid = EG;

                    OCMovers_MC4.Models.EstimateForm newEstimate = new OCMovers_MC4.Models.EstimateForm()
                    {
                        EstimateGuid         = EG,
                        Feedback             = estimateForm.Feedback,
                        InventoryWriteIn     = estimateForm.InventoryWriteIn,
                        InventoryItem        = estimateForm.InventoryItem,
                        IsDateFlexible       = estimateForm.IsDateFlexible,
                        PreviousCustomer     = estimateForm.PreviousCustomer,
                        PreviousCustomerName = estimateForm.PreviousCustomerName,
                        agreeCorrect         = estimateForm.agreeCorrect,
                        email           = estimateForm.email,
                        estBoxCount     = estimateForm.estBoxCount,
                        moveDateEnd     = estimateForm.moveDateEnd,
                        moveDescription = estimateForm.moveDescription,
                        name            = estimateForm.name,
                        packingServices = estimateForm.packingServices,
                        phone           = estimateForm.phone,

                        //old fields not required here
                        dwellingTypeCurrent               = estimateForm.dwellingTypeCurrent,
                        dwellingTypeCurrentFloorApt       = estimateForm.dwellingTypeCurrentFloorApt,
                        dwellingTypeCurrentFloorHouse     = estimateForm.dwellingTypeCurrentFloorHouse,
                        dwellingTypeDestination           = estimateForm.dwellingTypeDestination,
                        dwellingTypeDestinationFloorApt   = estimateForm.dwellingTypeDestinationFloorApt,
                        dwellingTypeDestinationFloorHouse = estimateForm.dwellingTypeDestinationFloorHouse,
                        loc1BuildingName      = estimateForm.loc1BuildingName,
                        loc1Address1          = estimateForm.loc1Address1,
                        loc1Address2          = estimateForm.loc1Address2,
                        loc1Apartment         = estimateForm.loc1Apartment,
                        loc1City              = estimateForm.loc1City,
                        loc1State             = estimateForm.loc1State,
                        loc1Postal            = estimateForm.loc1Postal,
                        loc2BuildingName      = estimateForm.loc2BuildingName,
                        loc2Address1          = estimateForm.loc2Address1,
                        loc2Address2          = estimateForm.loc2Address2,
                        loc2Apartment         = estimateForm.loc2Apartment,
                        loc2City              = estimateForm.loc2City,
                        loc2State             = estimateForm.loc2State,
                        loc2Postal            = estimateForm.loc2Postal,
                        elevStairsCurrent     = estimateForm.elevStairsCurrent,
                        elevStairsDestination = estimateForm.elevStairsDestination,
                        elevStairsResExp      = estimateForm.elevStairsResExp,
                        stairsToFrontExp      = estimateForm.stairsToFrontExp,
                        longWalksToDoorExp    = estimateForm.longWalksToDoorExp,
                        specialCareItemExp    = estimateForm.specialCareItemExp,
                        //Addresses = new List<Address>(),
                        elevStairsRes                       = estimateForm.elevStairsRes,
                        longWalksToDoor                     = estimateForm.longWalksToDoor,
                        numRoomsCurrent                     = estimateForm.numRoomsCurrent,
                        numRoomsDestination                 = estimateForm.numRoomsDestination,
                        specialCareItem                     = estimateForm.specialCareItem,
                        stairsToFront                       = estimateForm.stairsToFront,
                        submitDate                          = DateTime.Now,
                        StorageGroundFloorAccessCurrent     = estimateForm.StorageGroundFloorAccessCurrent,
                        StorageGroundFloorAccessDestination = estimateForm.StorageGroundFloorAccessDestination,
                        StorageTypeCurrent                  = estimateForm.StorageTypeCurrent,
                        StorageTypeDestination              = estimateForm.StorageTypeDestination,
                        OtherCurrent                        = estimateForm.OtherCurrent,
                        OtherDestination                    = estimateForm.OtherDestination
                    };

                    db.EstimateForm.Add(newEstimate);
                    db.SaveChanges();

                    //foreach (var a in addresses)
                    //{
                    //    var newAddress = new CustomerAddress()
                    //    {
                    //        AddressType = a.AddressType,
                    //        Address1 = a.Address1,
                    //        AptNum = a.AptNum,
                    //        BuildingName = a.BuildingName,
                    //        City = a.City,
                    //        EstimateId = newEstimate.EstimateFormID,
                    //        Postcode = a.Postcode,
                    //        State = a.State,
                    //        AptFloor = a.AptFloor ?? 0,
                    //        ElevatorStairs = a.ElevatorStairs,
                    //        ElevatorStairsDescription = a.ElevatorStairsDescription,
                    //        HouseOrApt = a.HouseOrApt,
                    //        HouseStories = a.HouseStories,
                    //        Inventory = a.Inventory,
                    //        LongWalks = a.LongWalks,
                    //        LongWalksDescription = a.LongWalksDescription,
                    //        Notes = a.Notes,
                    //        NumberOfBedrooms = a.NumberOfBedrooms,
                    //        SpecialCare = a.SpecialCare,
                    //        SpecialCareDescription = a.SpecialCareDescription,
                    //        Stairs = a.Stairs,
                    //        StairsDescription = a.StairsDescription,
                    //        BoxCount = a.BoxCount
                    //    };

                    //    db.CustomerAddress.Add(newAddress);
                    //    db.SaveChanges();
                    //}

                    //newEstimate.Addresses = addresses;

                    UserMailer.Welcome(newEstimate).Send();

                    return(new JsonResult()
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new { result = "success" }
                    });
                }
                else
                {
                    var es = ModelState.Where(x => x.Value.Errors.Count > 0)
                             .Select(x => new { x.Key, x.Value.Errors })
                             .ToArray();

                    var errors = ModelState
                                 .Where(x => x.Value.Errors.Count > 0)
                                 .Select(x => new { x.Key, x.Value.Errors })
                                 .ToArray();
                    Debug.WriteLine("Model state not valid");

                    StringBuilder sb = new StringBuilder();

                    foreach (var c in errors)
                    {
                        sb.Append(string.Concat(c.Key, ": ", c.Errors[0].ErrorMessage, "<br>"));
                    }

                    string output = sb.ToString();

                    CreateErrorLogEmail(output, null);

                    UserMailer.SendModelStateError(output).Send();

                    return(new JsonResult()
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new { result = output }
                    });

                    ;
                }
            }
            catch (Exception ex)
            {
                var str = new JavaScriptSerializer().Serialize(estimateForm);

                CreateErrorLogEmail(str, ex);

                throw;
            }
        }