public void Update(ProductionUnitOwnerViewModel currentProductionUnitOwnerViewModel) { ProductionUnitOwner target = new ProductionUnitOwner(); target = entities.ProductionUnitOwners.Where(p => p.Id == currentProductionUnitOwnerViewModel.Id).FirstOrDefault(); if (target != null) { target.pioneerCitizenNumber = currentProductionUnitOwnerViewModel.pioneerCitizenNumber; target.pioneerCitizenName = currentProductionUnitOwnerViewModel.pioneerCitizenName; target.contactMail = currentProductionUnitOwnerViewModel.contactMail; target.office365Account = currentProductionUnitOwnerViewModel.office365Mail; target.phoneNumber = currentProductionUnitOwnerViewModel.phoneNumber; target.location = currentProductionUnitOwnerViewModel.location; target.notificationPushKey = currentProductionUnitOwnerViewModel.notificationPushKey; ApplicationUser currentApplicationUser = new ApplicationUser(); currentApplicationUser = entities.Users.Where(p => p.Id == currentProductionUnitOwnerViewModel.userId).FirstOrDefault(); if (currentApplicationUser != null) { currentApplicationUser.Email = currentProductionUnitOwnerViewModel.contactMail; } Language currentLanguagee = new Language(); currentLanguagee = entities.Languages.Where(p => p.Id == currentProductionUnitOwnerViewModel.languageId).FirstOrDefault(); PreferedMoment currentPreferedMoment = new PreferedMoment(); currentPreferedMoment = entities.PreferedMoments.Where(p => p.Id == currentProductionUnitOwnerViewModel.preferedMomentId).FirstOrDefault(); } entities.SaveChanges(); }
public void Destroy(ProductionUnitOwnerViewModel currentProductionUnitOwnerViewModel) { ProductionUnitOwner currentProductionUnitOwner = new ProductionUnitOwner(); currentProductionUnitOwner = entities.ProductionUnitOwners.Where(p => p.Id == currentProductionUnitOwner.Id).FirstOrDefault(); entities.ProductionUnitOwners.Remove(currentProductionUnitOwner); entities.SaveChanges(); }
public static void ResetPasswordMessage(ProductionUnitOwner currentProductionUnitOwner, string to, string callbackUrl) { var client = new SendGridClient(MailSendGridAPIKey); var from = new EmailAddress("*****@*****.**", "Myfood Hub Bot"); MailTemplateObject obj = new MailTemplateObject(); var currentTemplate = string.Empty; var pioneerName = string.Format("{0} #{1}", currentProductionUnitOwner.pioneerCitizenName, currentProductionUnitOwner.pioneerCitizenNumber); obj.firstName = currentProductionUnitOwner.pioneerCitizenName; obj.pioneerNumber = currentProductionUnitOwner.pioneerCitizenNumber.ToString(); obj.callbackurl = callbackUrl; List <EmailAddress> tos = new List <EmailAddress> { new EmailAddress(currentProductionUnitOwner.contactMail, pioneerName) }; if (currentProductionUnitOwner != null && currentProductionUnitOwner.language != null) { switch (currentProductionUnitOwner.language.description) { case "fr": currentTemplate = TemplatePasswordRecoveryFR; break; case "en": currentTemplate = TemplatePasswordRecoveryEN; break; case "de": currentTemplate = TemplatePasswordRecoveryDE; break; default: currentTemplate = TemplatePasswordRecoveryEN; break; } } else { currentTemplate = TemplatePasswordRecoveryEN; } var msg = MailHelper.CreateSingleTemplateEmailToMultipleRecipients(from, tos, currentTemplate, obj); //msg.AddCc("*****@*****.**"); var response = client.SendEmailAsync(msg); }
public void Create(ProductionUnitOwnerViewModel currentProductionUnitOwnerViewModel) { PreferedMoment currentPreferedMoment = new PreferedMoment(); currentPreferedMoment = entities.PreferedMoments.Where(p => p.Id == currentProductionUnitOwnerViewModel.preferedMomentId).FirstOrDefault(); var entity = new ProductionUnitOwner(); entity.Id = currentProductionUnitOwnerViewModel.Id; entity.pioneerCitizenNumber = currentProductionUnitOwnerViewModel.pioneerCitizenNumber; entity.pioneerCitizenName = currentProductionUnitOwnerViewModel.pioneerCitizenName; entity.contactMail = currentProductionUnitOwnerViewModel.contactMail; entity.office365Account = currentProductionUnitOwnerViewModel.office365Mail; entity.phoneNumber = currentProductionUnitOwnerViewModel.phoneNumber; entity.location = currentProductionUnitOwnerViewModel.location; entity.notificationPushKey = currentProductionUnitOwnerViewModel.notificationPushKey; if (entity.user == null) { var user = entities.Users.Where(p => p.Id == currentProductionUnitOwnerViewModel.userId).FirstOrDefault(); entity.user = user; if (user != null) { user.Email = currentProductionUnitOwnerViewModel.contactMail; } } if (entity.language == null) { var language = entities.Languages.Where(p => p.Id == currentProductionUnitOwnerViewModel.languageId).FirstOrDefault(); entity.language = language; } if (entity.preferedMoment == null) { var preferedMoment = entities.PreferedMoments.Where(p => p.Id == currentProductionUnitOwnerViewModel.preferedMomentId).FirstOrDefault(); entity.preferedMoment = preferedMoment; } entities.ProductionUnitOwners.Add(entity); entities.SaveChanges(); currentProductionUnitOwnerViewModel.Id = entity.Id; }
public void Update(ProductionUnitViewModel productionUnit) { ProductionUnit target = new ProductionUnit(); target = entities.ProductionUnits.Where(p => p.Id == productionUnit.Id).Include(m => m.productionUnitType) .Include(m => m.productionUnitStatus) .Include(m => m.owner) .Include(m => m.hydroponicType).FirstOrDefault(); if (target != null) { target.startDate = productionUnit.startDate.Value; target.locationLatitude = productionUnit.locationLatitude; target.locationLongitude = productionUnit.locationLongitude; target.version = productionUnit.version; target.info = productionUnit.info; // target.options = productionUnit.options; target.reference = productionUnit.reference; target.picturePath = productionUnit.picturePath; target.lastMeasureReceived = productionUnit.lastMeasureReceived; ProductionUnitType currentProductionUnitType = new ProductionUnitType(); currentProductionUnitType = entities.ProductionUnitTypes.Where(p => p.Id == productionUnit.productionUnitTypeId).FirstOrDefault(); target.productionUnitType = currentProductionUnitType; HydroponicType currentHydroponicType = new HydroponicType(); currentHydroponicType = entities.HydroponicTypes.Where(p => p.Id == productionUnit.hydroponicTypeId).FirstOrDefault(); target.hydroponicType = currentHydroponicType; ProductionUnitStatus currentProductionUnitStatus = new ProductionUnitStatus(); currentProductionUnitStatus = entities.ProductionUnitStatus.Where(p => p.Id == productionUnit.productionUnitStatusId).FirstOrDefault(); target.productionUnitStatus = currentProductionUnitStatus; ProductionUnitOwner currentProductionUnitOwner = new ProductionUnitOwner(); currentProductionUnitOwner = entities.ProductionUnitOwners.Where(p => p.Id == productionUnit.ownerId).FirstOrDefault(); target.owner = currentProductionUnitOwner; } entities.SaveChanges(); }