Пример #1
0
        public ActionResult Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid && registerViewModel.validate(ModelState))
            {
                var db = new photogEntities();

                var veriKey = (new Backbone()).Random(8);

                User user = new User {
                    email = registerViewModel.Email.Trim().ToLower(), password = registerViewModel.Password, isVerified = false, verifiedKey = veriKey, name = registerViewModel.Email
                };
                user.UserSystemRoles.Add(new UserSystemRole {
                    systemroleid = 2
                });

                db.Users.Add(user);
                db.SaveChanges();

                string url          = string.Format("https://{0}/Account/Validate?key={1}", Request.Url.Authority, veriKey);
                string emailContent = String.Format("Click Here to verify Account : {0}", url);

                var client = new SmtpClient("smtp.titan.email", 587)
                {
                    Credentials = new NetworkCredential("*****@*****.**", "RareMaHZUU")
                };
                client.Send("*****@*****.**", user.email, "Verify your Account", emailContent);

                ViewBag.Email = registerViewModel.Email;
                return(View("ValidateEmail"));
            }
            return(View(registerViewModel));
        }
Пример #2
0
        public ActionResult ForgotPassword(ForgotPasswordViewModel forgot)
        {
            if (ModelState.IsValid && forgot.validate(ModelState))
            {
                photogEntities db    = new photogEntities();
                var            users = db.Users.FirstOrDefault(x => x.email.ToLower() == forgot.Email.ToLower());

                if (users != null)
                {
                    users.isForgotPassword = true;
                    users.verifiedKey      = (new Backbone()).Random(8);
                    db.SaveChanges();

                    string url          = string.Format("https://{0}/Account/Validate?key={1}", Request.Url.Authority, users.verifiedKey);
                    string emailContent = String.Format("Click Here to reset your password : {0}", url);

                    var client = new SmtpClient("smtp.titan.email", 587)
                    {
                        Credentials = new NetworkCredential("*****@*****.**", "RareMaHZUU")
                    };
                    client.Send("*****@*****.**", forgot.Email, "Verify your Account", emailContent);
                }

                ViewBag.Email = forgot.Email.ToLower();
                return(View("ValidateEmail"));
            }
            return(View("ForgotPasswordMain"));
        }
Пример #3
0
        public ActionResult ResetPassword(ResetPasswordViewModel forgot)
        {
            if (TempData["ForgotPasswordEmail"] != null && !string.IsNullOrWhiteSpace(forgot.Email))
            {
                if (ModelState.IsValid)
                {
                    photogEntities db    = new photogEntities();
                    var            users = db.Users.FirstOrDefault(x => x.email.ToLower() == forgot.Email.ToLower());

                    if (users != null)
                    {
                        var passwordHash = Backbone.ComputeSha256Hash(forgot.Password);

                        users.password = passwordHash;
                        db.SaveChanges();
                        TempData["ResetPasswordSuccess"] = "1";
                        return(RedirectToAction("SignIn", "Account"));
                    }
                }
                else
                {
                    TempData.Keep("ForgotPasswordEmail");
                    return(View(forgot));
                }
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #4
0
        public ActionResult CreateChat(int?package)
        {
            User whichuser = (User)UserAuthentication.Identity();
            long studioID  = (long)ViewBag.StudioID;

            var checkchatkey = ent.ChatKeys.FirstOrDefault(x => x.ChatKey_Key == "studiokey" + studioID + "userkey" + whichuser.id);

            if (checkchatkey == null)
            {
                checkchatkey             = new ChatKey();
                checkchatkey.ChatKey_Key = "studiokey" + studioID + "userkey" + whichuser.id;
                checkchatkey.UserID      = whichuser.id;

                checkchatkey.StudioID = (int)studioID;
                ent.ChatKeys.Add(checkchatkey);

                ent.SaveChanges();
            }

            if (package.HasValue)
            {
                TempData["Package"] = package;
            }
            return(Redirect(string.Format("/{0}?key={1}", "Chat", checkchatkey.ChatKeyID)));
        }
Пример #5
0
        public ActionResult Create(CreatePackageViewModel data)
        {
            if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid))
            {
                return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0)
                    {
                        TempData["error"] = "Invalid price setting";
                        return(View("editpackage", data));
                    }

                    var pack = new Package
                    {
                        depositprice = data.depoprice,
                        details      = string.IsNullOrWhiteSpace(data.details) ? null : data.details,
                        name         = data.name,
                        price        = data.price,
                        studioid     = data.studioid,
                        status       = "Enabled"
                    };

                    if (!string.IsNullOrWhiteSpace(data.ImgName))
                    {
                        PackageImage package = new PackageImage {
                            ImageName = data.ImgName
                        };
                        pack.PackageImages.Add(package);
                    }

                    db.Packages.Add(pack);
                    db.SaveChanges();
                    return(RedirectToAction("PackageHome"));
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Error500", "Home", new { errormsg = e.Message }));
                }
            }

            return(View("editpackage", data));
        }
Пример #6
0
        public ActionResult ChangeStudioUsername(Studio studio)
        {
            var regexItem = new Regex("^[a-zA-Z0-9]*$");

            ViewBag.IsStudioSetting = "2";

            photogEntities db       = new photogEntities();
            var            username = studio.uniquename?.Trim();

            studio            = db.Studios.FirstOrDefault(x => x.id == studio.id);
            studio.uniquename = username;
            var notAllowed = new string[] { "api", "systemapi", "database", "chat", "account", "studio", "payment", "package", "job", "jobc", "jobstatus", "home", "index", "hangfire" };

            if (string.IsNullOrWhiteSpace(username))
            {
                ModelState.AddModelError("uniquename", "Studio Username cannot be null");
            }
            else if (notAllowed.FirstOrDefault(x => x.ToLower() == username.ToLower()) != null)
            {
                ModelState.AddModelError("uniquename", "Entered username is not allowed");
            }

            else if (!regexItem.IsMatch(username))
            {
                ModelState.AddModelError("uniquename", "Studio Username cannot contain characters and spaces");
            }

            else if (username.Length > 20)
            {
                ModelState.AddModelError("uniquename", "Studio Username cannot be more than 20 words");
            }

            else
            {
                var checkUsername = db.Studios.FirstOrDefault(x => x.uniquename.ToLower() == username.ToLower() && x.id != studio.id);

                if (checkUsername != null)
                {
                    ModelState.AddModelError("uniquename", "Studio Username is already taken by other studio");
                }
            }

            if (ModelState.IsValid)
            {
                db.SaveChanges();

                TempData["Changes"] = "Studio Username have been changed successfully";
                return(Redirect(string.Format("/{0}/{1}", username, "Settings")));
            }

            return(View(studio));
        }
Пример #7
0
        public IHttpActionResult deletePackageCharges(int id)
        {
            photogEntities db    = new photogEntities();
            var            model = db.Charges.FirstOrDefault(x => x.id == id);

            if (model != null)
            {
                db.Charges.Remove(model);
                db.SaveChanges();
                return(Ok());
            }

            return(BadRequest());
        }
Пример #8
0
        public ActionResult Validate(string key)
        {
            var db = new photogEntities();

            var checkItem = db.Users.FirstOrDefault(x => x.verifiedKey.ToLower() == key.ToLower());

            if (checkItem == null)
            {
                return(new HttpUnauthorizedResult("Invalid Link"));
            }
            else if (checkItem.isVerified && checkItem.isForgotPassword)
            {
                checkItem.isForgotPassword      = false;
                checkItem.emailTemp             = null;
                checkItem.verifiedKey           = null;
                TempData["ForgotPasswordEmail"] = checkItem.email;
                return(RedirectToAction("ResetPassword", "Account"));
            }
            else if (checkItem.isVerified && string.IsNullOrWhiteSpace(checkItem.emailTemp))
            {
                return(new HttpUnauthorizedResult("Expired Link"));
            }
            if (!string.IsNullOrWhiteSpace(checkItem.emailTemp))
            {
                var check = db.Users.FirstOrDefault(x => x.email.ToLower() == checkItem.emailTemp.ToLower());

                if (check != null)
                {
                    return(new HttpUnauthorizedResult("Expired Link"));
                }

                checkItem.email     = checkItem.emailTemp;
                checkItem.emailTemp = null;
            }

            else
            {
                checkItem.isVerified = true;
            }

            checkItem.verifiedKey = null;
            db.SaveChanges();

            TempData["isVerified"] = "1";
            return(RedirectToAction("SignIn", "Account"));
        }
Пример #9
0
        public async System.Threading.Tasks.Task <IHttpActionResult> cancelJob(int id)
        {
            photogEntities db        = new photogEntities();
            var            job       = db.Jobs.FirstOrDefault(x => x.id == id);
            var            chatkey   = job.Package.Studio.ChatKeys.FirstOrDefault(x => x.UserID == job.userid).ChatKeyID;
            var            packageId = job.Package.id;

            if (job != null)
            {
                foreach (var item in job.Invoices.ToList())
                {
                    db.Invoices.Remove(item);
                }
                foreach (var item in job.JobCharges.ToList())
                {
                    db.JobCharges.Remove(item);
                }
                foreach (var item in job.JobDates.ToList())
                {
                    db.JobDates.Remove(item);
                }

                db.Jobs.Remove(job);
                db.SaveChanges();

                FirestoreDb firestore = FirestoreDb.Create("photogw2");

                var collection = firestore.Collection("Quotation");
                var query      = collection.WhereEqualTo("ChatKey", chatkey);
                var snapshot   = await query.GetSnapshotAsync();

                var deserializedDataQuoteAll = snapshot.FirstOrDefault().ConvertTo <QuotationModel>();
                var chat = db.ChatKeys.FirstOrDefault(x => x.ChatKeyID == deserializedDataQuoteAll.ChatKey);
                var deserializedDataSel = deserializedDataQuoteAll.Packages.FirstOrDefault(x => x.Package.Id == packageId);
                deserializedDataQuoteAll.Packages.Remove(deserializedDataSel);

                await collection.Document(snapshot.FirstOrDefault().Id).SetAsync(deserializedDataQuoteAll);

                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #10
0
        public IHttpActionResult UploadProfilePic()
        {
            var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                string    fl             = file.FileName;
                AzureBlob BlobManagerObj = new AzureBlob(1);
                string    FileName       = BlobManagerObj.UploadFileAPI(file, UserAuthentication.Identity().id.ToString());
                FileName = FileName.Substring(FileName.IndexOf('/') + 1);

                photogEntities db   = new photogEntities();
                var            id   = UserAuthentication.Identity().id;
                var            user = db.Users.FirstOrDefault(x => x.id == id);
                user.imgprofile = FileName;
                db.SaveChanges();

                UserAuthentication.UpdateClaim();

                return(Ok(FileName));
            }
            return(BadRequest());
        }
Пример #11
0
        public IHttpActionResult DeleteProfilePic()
        {
            var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                string fl = file.FileName;
                if (file.FileName == UserAuthentication.Identity().imgprofile)
                {
                    return(Ok());
                }
            }

            else
            {
                AzureBlob      BlobManagerObj = new AzureBlob(1);
                photogEntities db             = new photogEntities();
                var            id             = UserAuthentication.Identity().id;
                var            user           = db.Users.FirstOrDefault(x => x.id == id);

                if (user.imgprofile == null)
                {
                    return(Ok());
                }

                else if (!string.IsNullOrWhiteSpace(BlobManagerObj.DeleteBlob(user.id.ToString(), User.Identity.GetProfilePhotoLink())))
                {
                    user.imgprofile = null;
                    db.SaveChanges();

                    UserAuthentication.UpdateClaim();

                    return(Ok());
                }
            }
            return(BadRequest());
        }
Пример #12
0
        public ActionResult Edit(ProfileViewModel profile)
        {
            photogEntities db     = new photogEntities();
            var            userID = UserAuthentication.Identity().id;
            var            user   = db.Users.FirstOrDefault(x => x.id == userID);

            if (ModelState.IsValid)
            {
                if (profile.EditID == 1)
                {
                    user.name = profile.Name;
                }
                else if (profile.EditID == 2)
                {
                    user.phonenumber = profile.PhoneNum;
                }

                else if (profile.EditID == 3)
                {
                    if (user.email.ToLower() == profile.Email.ToLower())
                    {
                        ModelState.AddModelError("Email", "Email is same with existing email");
                    }

                    else if (db.Users.FirstOrDefault(x => x.id != user.id && x.email.ToLower() == profile.Email.ToLower()) != null)
                    {
                        ModelState.AddModelError("Email", "Email already exists");
                    }

                    if (!ModelState.IsValid)
                    {
                        profile = new ProfileViewModel {
                            Email = profile.Email, Name = user.name, PhoneNum = user.phonenumber
                        };
                        return(View(profile));
                    }

                    var    veriKey      = (new Backbone()).Random(8);
                    string url          = string.Format("https://{0}/Account/Validate?key={1}", Request.Url.Authority, veriKey);
                    string emailContent = String.Format("Click Here to verify your new Email : {0}", url);

                    var client = new SmtpClient("smtp.titan.email", 587)
                    {
                        Credentials = new NetworkCredential("*****@*****.**", "RareMaHZUU")
                    };
                    client.Send("*****@*****.**", profile.Email, "Verify your new Email", emailContent);

                    user.emailTemp   = profile.Email;
                    user.verifiedKey = veriKey;

                    TempData["Email"] = "An email has been sent to " + profile.Email + ", Please check your inbox to validate your email address change";
                }

                else
                {
                    var checkold = Backbone.ComputeSha256Hash(profile.OldPassword).ToLower();
                    if (checkold != user.password.ToLower())
                    {
                        ModelState.AddModelError("OldPassword", "Invalid old password");
                    }
                    else if (profile.NewPassword != profile.ConfirmPassword)
                    {
                        ModelState.AddModelError("NewPassword", "New Password does not match");
                    }
                    if (!ModelState.IsValid)
                    {
                        profile = new ProfileViewModel {
                            Email = user.email, Name = user.name, PhoneNum = user.phonenumber
                        };
                        return(View(profile));
                    }

                    var passwordHash = Backbone.ComputeSha256Hash(profile.NewPassword);
                    user.password = passwordHash;
                }

                TempData["SuccessMessage"] = "Changes has been saved successfully";

                db.SaveChanges();
                UserAuthentication.UpdateClaim();
                return(RedirectToAction("Edit", "Account"));
            }

            profile = new ProfileViewModel {
                Email = user.email, Name = user.name, PhoneNum = user.phonenumber
            };
            return(View(profile));
        }
Пример #13
0
        public async System.Threading.Tasks.Task <ActionResult> statusPayment(string id)
        {
            try
            {
                var service = new PaymentIntentService();
                var intent  = service.Get(id);
                if (intent.Status.Contains("succeeded"))
                {
                    int iid         = int.Parse(intent.Metadata["invoiceID"]);
                    var transaction = new Models.Database.Transaction
                    {
                        invoiceid       = iid,
                        paymentmethodid = 1,
                        reference       = id,
                        total           = decimal.Parse((Convert.ToDecimal(intent.Amount) / 100).ToString(".00")),
                        transdate       = DateTime.Now
                    };
                    db.Transactions.Add(transaction);
                    db.SaveChanges();

                    var invoice = db.Invoices.Find(iid);
                    //invoice.totalunpaid -= decimal.Parse((intent.Amount / 100).ToString(".00"));
                    //invoice.status = "Paid";
                    //db.Entry(invoice).State = System.Data.Entity.EntityState.Modified;
                    //db.SaveChanges();

                    //var job = db.Jobs.Find(invoice.jobid);
                    //job.jobstatusid = 1;
                    //db.SaveChanges();

                    //Remove Data from Firebase (Quoted Items)
                    var userTrans = db.Transactions.Where(x => x.Invoice.jobid == invoice.jobid);
                    if (userTrans.Count() == 1)
                    {
                        var userInvoice = userTrans.FirstOrDefault().Invoice.Job;
                        var package     = userInvoice.Package;
                        var userid      = userInvoice.User.id;
                        var chatkey     = package.Studio.ChatKeys.FirstOrDefault(x => x.UserID == userid).ChatKeyID;

                        FirestoreDb firestore = FirestoreDb.Create("photogw2");

                        var collection = firestore.Collection("Quotation");
                        var query      = collection.WhereEqualTo("ChatKey", chatkey);
                        var snapshot   = await query.GetSnapshotAsync();

                        var deserializedDataQuoteAll = snapshot.FirstOrDefault().ConvertTo <QuotationModel>();

                        var chat = db.ChatKeys.FirstOrDefault(x => x.ChatKeyID == deserializedDataQuoteAll.ChatKey);
                        var deserializedDataSel = deserializedDataQuoteAll.Packages.FirstOrDefault(x => x.Package.Id == package.id);

                        deserializedDataQuoteAll.Packages.Remove(deserializedDataSel);

                        await collection.Document(snapshot.FirstOrDefault().Id).SetAsync(deserializedDataQuoteAll);
                    }

                    return(View("success", db.Transactions.FirstOrDefault(x => x.invoiceid == iid)));
                }
                else
                {
                    return(View("cancel"));
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Error500", "Home", new { errormsg = e.Message }));
            }
        }
Пример #14
0
        public ActionResult Settings(CreateStudioViewModel createStudio)
        {
            createStudio.name          = createStudio.name?.Trim();
            createStudio.SelectedCity  = createStudio.SelectedCity?.Trim();
            createStudio.SelectedState = createStudio.SelectedState?.Trim();

            ViewBag.IsStudioSetting = "1";
            ViewBag.Header          = "Studio Settings";

            if (db.Studios.FirstOrDefault(x => x.name.ToLower() == createStudio.name.ToLower() && x.id != createStudio.id) != null)
            {
                ModelState.AddModelError("name", "Studio Name is not available");
            }

            if (!string.IsNullOrWhiteSpace(createStudio.phoneNum) && !int.TryParse(createStudio.phoneNum, out int result))
            {
                ModelState.AddModelError("phoneNum", "Invalid Phone Number");
            }

            if (!string.IsNullOrWhiteSpace(createStudio.email) && !Backbone.IsValidEmail(createStudio.email))
            {
                ModelState.AddModelError("email", "Invalid Email Address");
            }

            if (ModelState.IsValid)
            {
                var studio = db.Studios.FirstOrDefault(x => x.id == createStudio.id);

                AzureBlob blob = new AzureBlob(4);
                try
                {
                    blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgLogo);
                    studio.ImgLogo = createStudio.ImgLogo;
                }
                catch { }

                try
                {
                    blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgCover);
                    studio.ImgCover = createStudio.ImgCover;
                }
                catch { }

                studio.name      = createStudio.name;
                studio.shortDesc = createStudio.shortDesc;
                studio.phoneNum  = createStudio.phoneNum;
                studio.email     = createStudio.email;
                studio.State     = createStudio.SelectedState;
                studio.City      = createStudio.SelectedCity;
                studio.longDesc  = createStudio.longDesc;

                if (!string.IsNullOrWhiteSpace(createStudio.Facebook) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "facebook") == null)
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Facebook", address = createStudio.Facebook
                    });
                }

                if (!string.IsNullOrWhiteSpace(createStudio.Twitter) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "twitter") == null)
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Twitter", address = createStudio.Twitter
                    });
                }

                if (!string.IsNullOrWhiteSpace(createStudio.Instagram) && studio.StudioLinks.FirstOrDefault(x => x.name.ToLower() == "instagram") == null)
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Instagram", address = createStudio.Instagram
                    });
                }

                for (int i = 0; i < studio.StudioLinks.Count(); i++)
                {
                    if (studio.StudioLinks.ElementAt(i).name.ToLower() == "facebook")
                    {
                        if (string.IsNullOrWhiteSpace(createStudio.Facebook))
                        {
                            studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i));
                        }
                        else
                        {
                            studio.StudioLinks.ElementAt(i).address = createStudio.Facebook;
                        }
                    }
                    else if (studio.StudioLinks.ElementAt(i).name.ToLower() == "twitter")
                    {
                        if (string.IsNullOrWhiteSpace(createStudio.Twitter))
                        {
                            studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i));
                        }
                        else
                        {
                            studio.StudioLinks.ElementAt(i).address = createStudio.Twitter;
                        }
                    }
                    else if (studio.StudioLinks.ElementAt(i).name.ToLower() == "instagram")
                    {
                        if (string.IsNullOrWhiteSpace(createStudio.Instagram))
                        {
                            studio.StudioLinks.Remove(studio.StudioLinks.ElementAt(i));
                        }
                        else
                        {
                            studio.StudioLinks.ElementAt(i).address = createStudio.Instagram;
                        }
                    }
                }

                db.SaveChanges();

                TempData["Changes"] = "Studio profile have been updated successfully";
                return(Redirect(string.Format("/{0}/{1}", ViewBag.StudioUrl, "Settings")));
            }

            return(View(createStudio));
        }
Пример #15
0
        public ActionResult createjobstatus(JobStatu data)
        {
            if (!UserAuthentication.Identity().UserSystemRoles.Any(x => x.systemroleid == 1))
            {
                return(View("error"));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    db.JobStatus.Add(data);
                    db.SaveChanges();

                    return(Redirect("/JobStatus"));
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Error500", "Home", new { errormsg = e.Message }));
                }
            }

            return(View(data));
        }
Пример #16
0
        //[StudioAPIValidate(RoleID = 1)]
        public IHttpActionResult SetRoleList(RoleModel role)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    photogEntities db   = new photogEntities();
                    var            user = db.Users.FirstOrDefault(x => x.email.ToLower() == role.Email.ToLower().Trim());
                    if (user == null)
                    {
                        return(BadRequest("User email does not exist"));
                    }

                    else if (!user.isVerified)
                    {
                        return(BadRequest("User is not verified."));
                    }

                    if (role.Operation == 1)
                    {
                        var userStudio = user.UserStudios.FirstOrDefault(x => x.studioid == StudioID);
                        if (userStudio == null)
                        {
                            db.UserStudios.Add(new UserStudio {
                                studioid = StudioID, userid = user.id, studioroleid = role.Role
                            });
                        }
                        else if (userStudio.isActive == false)
                        {
                            userStudio.isActive = true;
                        }

                        else
                        {
                            return(BadRequest("User already registered with this Studio"));
                        }

                        db.SaveChanges();
                        return(Ok("User has been added successfully"));
                    }

                    else if (role.Operation == 2)
                    {
                        var userStudio = user.UserStudios.FirstOrDefault(x => x.studioid == StudioID);

                        if (userStudio == null)
                        {
                            return(BadRequest("User is not registered with this Studio"));
                        }

                        userStudio.studioroleid = role.Role;
                        db.SaveChanges();
                        return(Ok("User role have been updated"));
                    }

                    else if (role.Operation == 3)
                    {
                        var userStudio = user.UserStudios.FirstOrDefault(x => x.studioid == StudioID);

                        if (userStudio == null)
                        {
                            return(BadRequest("User is not registered with this Studio"));
                        }
                        else if (userStudio.userid == UserAuthentication.Identity().id)
                        {
                            return(BadRequest("Cannot delete your own profile from studio!"));
                        }
                        else if (db.UserStudios.Where(x => x.id != userStudio.id && x.studioroleid == 1).Count() <= 0)
                        {
                            return(BadRequest("No Admin Detected. Please assign other admin before removing account"));
                        }
                        else if (userStudio.JobDateUsers.Count() != 0)
                        {
                            userStudio.isActive = false;
                        }
                        else
                        {
                            db.UserStudios.Remove(userStudio);
                        }

                        db.SaveChanges();
                        return(Ok("User role have been deleted"));
                    }
                }
                return(BadRequest("Invalid Request"));
            }

            catch
            {
                return(InternalServerError());
            }
        }
Пример #17
0
        public ActionResult Create(CreateStudioViewModel createStudio)
        {
            createStudio.name          = createStudio.name?.Trim();
            createStudio.SelectedCity  = createStudio.SelectedCity?.Trim();
            createStudio.SelectedState = createStudio.SelectedState?.Trim();

            ViewBag.IsStudioSetting = "true";
            ViewBag.Header          = "Create New Studio";
            ViewBag.IsStudioSetting = "1";

            if (string.IsNullOrWhiteSpace(createStudio.name))
            {
                ModelState.AddModelError("name", "Studio Name cannot be null");
            }

            else
            {
                if (db.Studios.FirstOrDefault(x => x.name.ToLower() == createStudio.name.ToLower()) != null)
                {
                    ModelState.AddModelError("name", "Studio Name is not available");
                }
            }

            if (!string.IsNullOrWhiteSpace(createStudio.phoneNum) && !int.TryParse(createStudio.phoneNum, out int result))
            {
                ModelState.AddModelError("phoneNum", "Invalid Phone Number");
            }

            if (!string.IsNullOrWhiteSpace(createStudio.email) && !Backbone.IsValidEmail(createStudio.email))
            {
                ModelState.AddModelError("email", "Invalid Email Address");
            }

            if (ModelState.IsValid)
            {
                var studio = new Studio();
                studio.name       = createStudio.name;
                studio.shortDesc  = createStudio.shortDesc;
                studio.phoneNum   = createStudio.phoneNum;
                studio.email      = createStudio.email;
                studio.State      = createStudio.SelectedState;
                studio.City       = createStudio.SelectedCity;
                studio.longDesc   = createStudio.longDesc;
                studio.uniquename = (new Backbone()).Random(5);


                if (!string.IsNullOrWhiteSpace(createStudio.Facebook))
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Facebook", address = createStudio.Facebook
                    });
                }

                if (!string.IsNullOrWhiteSpace(createStudio.Twitter))
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Twitter", address = createStudio.Twitter
                    });
                }

                if (!string.IsNullOrWhiteSpace(createStudio.Instagram))
                {
                    studio.StudioLinks.Add(new StudioLink {
                        name = "Instagram", address = createStudio.Instagram
                    });
                }

                UserStudio userCred = new UserStudio {
                    userid = UserAuthentication.Identity().id, studioroleid = 1
                };
                studio.UserStudios.Add(userCred);

                db.Studios.Add(studio);
                db.SaveChanges();

                AzureBlob blob = new AzureBlob(4);
                try
                {
                    blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgLogo);
                    studio.ImgLogo = createStudio.ImgLogo;
                }
                catch { }

                try
                {
                    blob.MoveBlobFromTemp(2, studio.id.ToString(), createStudio.ImgCover);
                    studio.ImgCover = createStudio.ImgCover;
                }
                catch { }

                db.SaveChanges();
                return(Redirect(string.Format("/{0}", studio.uniquename)));
            }

            return(View("~/Views/StudioPermalink/Settings.cshtml", createStudio));
        }
Пример #18
0
        public async System.Threading.Tasks.Task <IHttpActionResult> PostPackageQuote(PostPackage data)
        {
            FirestoreDb firestore  = FirestoreDb.Create("photogw2");
            var         collection = firestore.Collection("Quotation").Document(data.data);
            var         snapshot   = await collection.GetSnapshotAsync();

            if (!snapshot.Exists)
            {
                return(BadRequest());
            }

            var deserializedDataQuoteAll = snapshot.ConvertTo <QuotationModel>();

            photogEntities db                  = new photogEntities();
            int            package             = Convert.ToInt32(data.package);
            var            chat                = db.ChatKeys.FirstOrDefault(x => x.ChatKeyID == deserializedDataQuoteAll.ChatKey);
            var            deserializedDataSel = deserializedDataQuoteAll.Packages.Select((x, index) => new { x, index }).FirstOrDefault(x => x.x.Package.Id == package);
            var            deserializedData    = deserializedDataSel.x;

            var job = new Job
            {
                packageid    = (int)deserializedData.Package.Id,
                userid       = chat.UserID.Value,
                jobstatusid  = db.JobStatus.FirstOrDefault(x => x.name.ToLower() == "pending deposit").id,
                DateCreated  = DateTime.Now,
                PackagePrice = Decimal.Parse(deserializedData.Package.Price.ToString()),
                TotalPrice   = decimal.Parse((deserializedData.Charges.Sum(x => (x.Quantity * x.PricePerUnit)) + deserializedData.Package.Price).ToString())
            };

            if (deserializedData.Charges != null && deserializedData.Charges.Count() != 0)
            {
                foreach (var item in deserializedData.Charges)
                {
                    job.JobCharges.Add(new JobCharge {
                        amount = (decimal)(item.Quantity * item.PricePerUnit), remarks = item.Remarks
                    });
                }
            }

            if (deserializedData.Venues != null && deserializedData.Venues.Count() != 0)
            {
                foreach (var item in deserializedData.Venues)
                {
                    job.JobDates.Add(new JobDate {
                        jobdate1 = item.Date, location = item.Location, jobstatusid = 6
                    });
                }
            }

            db.Jobs.Add(job);
            db.SaveChanges();

            deserializedData.OrderStatus = job.JobStatu.name;
            deserializedData.JobLink     = string.Format("/jobc/JobCustomerDetail/{0}", job.id.ToString());
            deserializedData.JobID       = job.id.ToString();
            deserializedData.StudioUrl   = chat.Studio.uniquename;

            deserializedDataQuoteAll.Packages[deserializedDataSel.index] = deserializedData;

            await collection.SetAsync(deserializedDataQuoteAll);

            return(Ok());
        }