public bool checkIfValidDuration()//returns true if duration is bigger than 0 { if (Duration > 0) { return(true); } FormErrors.Add("Duration must be a positive integer bigger than 0!\n"); return(false); }
public bool checkIfValidPhoneNumber()//returns true if phone number is in correct format { if (Regex.IsMatch(PhoneNumber, @"[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")) { return(true); } FormErrors.Add("Phone Number must be in vald Format! XXX-XXX-XXXX\n"); return(false); }
public bool checkIfAllPropertiesEntered() //returns true if all fields are non-empty { if (this.GetType().GetProperties().All(p => p.GetValue(this) != null)) //uses lambda expression to ensure all properties are not null { return(true); } FormErrors.Add("Please enter all required Fields!\n"); return(false); }
public bool checkIfValidEmail()//returns true if email entered is in correct format { if (Regex.IsMatch(Email, @".+@.+.com")) { return(true); } FormErrors.Add("Email must be in Valid Format! {...}@{...}.com\n"); return(false); }
public ActionResult Index() { var errors = new FormErrors(); foreach (string entry in Request.Form.Keys) { var value = Request.Form[entry]; if (string.IsNullOrEmpty(value)) { errors.messages[entry] = "Value is missing"; errors.Add(entry); } } var form = new Form(); if (errors.Count != 0) { form.posted_successfully = false; form.errors = errors; } else { form.posted_successfully = true; } TempData["form"] = form; var storeOwner = MASTERdomain.organisation.users.First(); var formType = Request.Form["form_type"]; var email = Request.Form["email"]; if (!string.IsNullOrEmpty(formType) && formType == "customer") { // add contact to contact list // check if email exists var usr = repository.GetUsersByEmail(email, subdomainid.Value).SingleOrDefault(); if (usr == null) { // create org var org = new organisation { name = email, subdomain = subdomainid.Value }; var orgid = repository.AddOrganisation(org); // create user usr = new user { role = (int)UserRole.USER, email = email, viewid = Crypto.Utility.GetRandomString(), permissions = (int)UserPermission.USER, organisation = orgid }; repository.AddUser(usr); } // add to contact group if (!string.IsNullOrEmpty(Request.Form["group"])) { var group = MASTERdomain.contactGroups.Where(x => x.title == Request.Form["group"]).SingleOrDefault(); if (group == null) { group = new contactGroup() { title = Request.Form["group"] }; MASTERdomain.contactGroups.Add(group); } if (group.contactGroupMembers.AsQueryable().Where(x => x.userid == usr.id).SingleOrDefault() == null) { group.contactGroupMembers.Add(new contactGroupMember { userid = usr.id }); } } repository.Save(); } else { // send notification email to store owner var viewdata = new NewMessage { name = Request.Form["name"], email = email, message = Request.Form["body"].ToHtmlBreak() }; this.SendEmail(EmailViewType.STORE_NEWMESSAGE, viewdata, "New Store Message", storeOwner.GetEmailAddress(), storeOwner.ToFullName(), null); } return(Redirect(Request.UrlReferrer.ToString())); }