/// <summary> /// Register worlref user /// </summary> /// <param name="signModel"></param> /// <returns></returns> public string Add(SignUpWorldRefModel signModel) { string ReturnStatus = "Success"; string UserRole = "W"; try { RegisterUser register = new RegisterUser() { UserFirstName = signModel.Name, Company = signModel.Name, Type = signModel.Type, Email = signModel.Email, phone = signModel.ContactNumber, Industries = signModel.Industry, OfficialNumber = signModel.OfficialNumber, CountryName = signModel.Country.ToString(), BusinessInterestCountry = signModel.BusinessInterestCountry.ToString(), ProfileAttach = signModel.ProfilePath, PhotoAttach = signModel.ProfileFileName, UserNo = signModel.UserName, Password = signModel.Password, UserRole = UserRole, UploaderType = signModel.UploaderType, OrganisationName = signModel.OrganisationName, BussinessUnitName = signModel.BusinessUnitName, MyCompany = signModel.MyCompany, RecoveryMail = signModel.RecoveryMail, OtherMail = signModel.OtherMail, ProfileUrl = signModel.ProfileUrl, ProfileLanguageID = Convert.ToInt16(signModel.Language), Date = DateTime.Now }; context.RegisterUsers.Add(register); context.SaveChanges(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(ReturnStatus); }
public string AddLikeOrDislike(int ProjectId, string LikeOrDisLike, string Comment, string Null) { string ReturnString = "Success"; try { ProjectLikeDisLike projectLike = (from likeTb in context.ProjectLikeDisLikes where likeTb.projectId == ProjectId select likeTb).FirstOrDefault(); if (projectLike != null) { int?TotalLike = projectLike.totalLike; int?TotalDisLike = Convert.ToInt32(projectLike.totalDislike); if (LikeOrDisLike == "Like") { projectLike.totalLike = TotalLike + 1; } else { projectLike.totalDislike = (TotalDisLike + 1).ToString(); } } else { ProjectLikeDisLike projectLikeDislike = new ProjectLikeDisLike(); projectLikeDislike.projectId = ProjectId; if (LikeOrDisLike == "Like") { projectLikeDislike.totalLike = 1; projectLikeDislike.totalDislike = "0"; } else { projectLikeDislike.totalLike = 0; projectLikeDislike.totalDislike = "1"; } context.ProjectLikeDisLikes.Add(projectLikeDislike); } ProjectLikeComment projectComent = new ProjectLikeComment(); projectComent.projectId = ProjectId; projectComent.comment = Comment; projectComent.date = DateTime.Now; context.ProjectLikeComments.Add(projectComent); context.SaveChanges(); } catch { ReturnString = "Fail"; } return(ReturnString); }
public static bool InitialiseDiary() { // init connection to database I4IDBEntities ent = new I4IDBEntities(); try { for (int i = 0; i < 30; i++) { AppointmentDiary item = new AppointmentDiary(); // record ID is auto generated item.Title = "Appt: " + i.ToString(); item.SomeImportantKey = i; item.StatusENUM = GetRandomValue(0, 3); // random is exclusive - we have three status enums if (i <= 5) // create a few appointments for todays date { item.DateTimeScheduled = GetRandomAppointmentTime(false, true); } else { // rest of appointments on previous and future dates if (i % 2 == 0) item.DateTimeScheduled = GetRandomAppointmentTime(true, false); // flip/flop between date ahead of today and behind today else item.DateTimeScheduled = GetRandomAppointmentTime(false, false); } item.AppointmentLength = GetRandomValue(1, 5) * 15; // appoiment length in blocks of fifteen minutes in this demo ent.AppointmentDiaries.Add(item); ent.SaveChanges(); } } catch (Exception) { return false; } return ent.AppointmentDiaries.Count() > 0; }
public int AddIndustry(string IndustryName) { int industryId = (from indu in context.Industries where indu.IndustriesName.ToLower() == IndustryName.ToLower() select indu.IndustriesID ).FirstOrDefault(); if (industryId == 0) { context.Industries.Add(new WorldRef.Industry() { IndustriesName = IndustryName }); context.SaveChanges(); } return(industryId); }
public static void UpdateDiaryEvent(int id, string NewEventStart, string NewEventEnd) { // EventStart comes ISO 8601 format, eg: "2000-01-10T10:00:00Z" - need to convert to DateTime using (I4IDBEntities ent = new I4IDBEntities()) { var rec = ent.AppointmentDiaries.FirstOrDefault(s => s.AppointmentID == id); if (rec != null) { DateTime DateTimeStart = DateTime.Parse(NewEventStart, null, DateTimeStyles.RoundtripKind).ToLocalTime(); // and convert offset to localtime rec.DateTimeScheduled = DateTimeStart; if (!String.IsNullOrEmpty(NewEventEnd)) { TimeSpan span = DateTime.Parse(NewEventEnd, null, DateTimeStyles.RoundtripKind).ToLocalTime() - DateTimeStart; rec.AppointmentLength = Convert.ToInt32(span.TotalMinutes); } ent.SaveChanges(); } } }
public static bool CreateNewEvent(string Title, string NewEventDate) { try { I4IDBEntities ent = new I4IDBEntities(); AppointmentDiary rec = new AppointmentDiary(); string userNoCookiesVale = HttpContext.Current.Request.Cookies["UserNo"].Value; var result =(from r in ent.RegisterUsers where r.UserNo==userNoCookiesVale && r.UserRole=="T" select new { r.Id }); rec.id = Convert.ToInt32(result.FirstOrDefault().Id); rec.Title = Title; DateTime dt = DateTime.ParseExact(NewEventDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); rec.DateTimeScheduled = dt; //rec.AppointmentLength = Int32.Parse(NewEventDuration); ent.AppointmentDiaries.Add(rec); ent.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; return false; } return true; }
public static bool InitialiseDiary() { // init connection to database I4IDBEntities ent = new I4IDBEntities(); try { for (int i = 0; i < 30; i++) { AppointmentDiary item = new AppointmentDiary(); // record ID is auto generated item.Title = "Appt: " + i.ToString(); item.SomeImportantKey = i; item.StatusENUM = GetRandomValue(0, 3); // random is exclusive - we have three status enums if (i <= 5) // create a few appointments for todays date { item.DateTimeScheduled = GetRandomAppointmentTime(false, true); } else { // rest of appointments on previous and future dates if (i % 2 == 0) { item.DateTimeScheduled = GetRandomAppointmentTime(true, false); // flip/flop between date ahead of today and behind today } else { item.DateTimeScheduled = GetRandomAppointmentTime(false, false); } } item.AppointmentLength = GetRandomValue(1, 5) * 15; // appoiment length in blocks of fifteen minutes in this demo ent.AppointmentDiaries.Add(item); ent.SaveChanges(); } } catch (Exception) { return(false); } return(ent.AppointmentDiaries.Count() > 0); }
public static bool CreateNewEvent(string Title, string NewEventDate) { try { I4IDBEntities ent = new I4IDBEntities(); AppointmentDiary rec = new AppointmentDiary(); string userNoCookiesVale = HttpContext.Current.Request.Cookies["UserNo"].Value; var result = (from r in ent.RegisterUsers where r.UserNo == userNoCookiesVale && r.UserRole == "T" select new { r.Id }); rec.id = Convert.ToInt32(result.FirstOrDefault().Id); rec.Title = Title; DateTime dt = DateTime.ParseExact(NewEventDate, "dd/MM/yyyy", CultureInfo.InvariantCulture); rec.DateTimeScheduled = dt; //rec.AppointmentLength = Int32.Parse(NewEventDuration); ent.AppointmentDiaries.Add(rec); ent.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; return(false); } return(true); }
public static void UpdateDiaryEvent(int id, string NewEventStart, string NewEventEnd) { // EventStart comes ISO 8601 format, eg: "2000-01-10T10:00:00Z" - need to convert to DateTime using ( I4IDBEntities ent = new I4IDBEntities()) { var rec = ent.AppointmentDiaries.FirstOrDefault(s => s.AppointmentID == id); if (rec != null) { DateTime DateTimeStart = DateTime.Parse(NewEventStart, null, DateTimeStyles.RoundtripKind).ToLocalTime(); // and convert offset to localtime rec.DateTimeScheduled = DateTimeStart; if (!String.IsNullOrEmpty(NewEventEnd)) { TimeSpan span = DateTime.Parse(NewEventEnd, null, DateTimeStyles.RoundtripKind).ToLocalTime() - DateTimeStart; rec.AppointmentLength = Convert.ToInt32(span.TotalMinutes); } ent.SaveChanges(); } } }
public ActionResult SavePromotion(FormCollection fc, HttpPostedFileBase[] file, HttpPostedFileBase[] file1, HttpPostedFileBase[] file2, HttpPostedFileBase[] file3, string chkvalue) { PromotionLibrary _objPromotion = new PromotionLibrary(); string result = fc["AllData"]; string result1 = fc["AllData1"]; string result2 = fc["AllData2"]; _objPromotion.PName = fc["PName"]; _objPromotion.PEmailId = fc["PEmailId"]; _objPromotion.PContactNumber = fc["PContactNumber"]; if (file[0] != null) { _objPromotion.PReference = file[0].FileName; file[0].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objPromotion.PReference)); } if (file[1] != null) { _objPromotion.PCompanyProfile = file[1].FileName; file[1].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objPromotion.PCompanyProfile)); } // _objPromotion.IndustriesID = Convert.ToInt32(fc["IndustriesID"]); _objPromotion.Status = "A"; _objPromotion.IsActive = false; db.PromotionLibraries.Add(_objPromotion); db.SaveChanges(); var lastID = _objPromotion.PromotionLibraryID; string[] abc = result.Split('~'); PromotionProductList _objproduct = new PromotionProductList(); for (int i = 0; i < abc.Count() - 1; i++) { _objproduct.PromotionLibraryID = Convert.ToInt32(lastID); _objproduct.ProductName = abc[i].Split(',')[0]; _objproduct.ProductIndustry = abc[i].Split(',')[1]; if (file1[i] != null) { _objproduct.ProductBrochure = file1[i].FileName; file1[i].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objproduct.ProductBrochure)); } if (file1[i + 1] != null) { _objproduct.URSFormat = file1[i + 1].FileName; file1[i + 1].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objproduct.URSFormat)); } db.PromotionProductLists.Add(_objproduct); db.SaveChanges(); } PromotionCertificate _objprmCertificate = new PromotionCertificate(); string[] mno = result1.Split('~'); for (int i = 0; i < mno.Count() - 1; i++) { _objprmCertificate.PromotionLibraryID = Convert.ToInt32(lastID); _objprmCertificate.CertificateName = mno[i]; if (file2[i] != null) { _objprmCertificate.CertificateAttachment = file2[i].FileName; } file2[i].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objprmCertificate.CertificateAttachment)); } db.PromotionCertificates.Add(_objprmCertificate); db.SaveChanges(); PromotionOtherDocument _objprmOtherDocument = new PromotionOtherDocument(); string[] xyz = result2.Split('~'); for (int i = 0; i < xyz.Count() - 1; i++) { _objprmOtherDocument.PromotionLibraryID = Convert.ToInt32(lastID); _objprmOtherDocument.OtherDocumentName = xyz[i]; if (file3[i] != null) { _objprmOtherDocument.DocumentAttachment = file3[i].FileName; } file3[i].SaveAs(Server.MapPath("~/Content/PromotionFile/" + _objprmOtherDocument.DocumentAttachment)); } db.PromotionOtherDocuments.Add(_objprmOtherDocument); db.SaveChanges(); string[] ch = chkvalue.Split(','); PromotionIndustry objProIndustry = new PromotionIndustry(); for (int i = 0; i < ch.Count(); i++) { objProIndustry.PromotionLibraryID = Convert.ToInt32(lastID); objProIndustry.IndustriesID = Convert.ToInt32(ch[i]); db.PromotionIndustries.Add(objProIndustry); db.SaveChanges(); } TempData["Data"] = "Thanks for sharing your material with i4i.<br/> Your request has been received and is subjected to approval from i4i."; TempData["vColor"] = "green"; return(RedirectToAction("PromotionLibraryForm")); }