public async Task SetMandateTest() { //given var manager = new SmartContractManager(); var mandate = new MandateModel { Email = "*****@*****.**", MobileNumber = "1234567890", SmartMeter = new MandateType { Active = true, StartDate = "2016-12-12", EndDate = "2017-12-12" }, SourceProfile = new MandateType { Active = true, StartDate = "2016-12-12", EndDate = "2017-12-12" }, TrustedParty = new MandateType { Active = true, StartDate = "2016-12-12", EndDate = "2017-12-12" } }; //when var actual = await manager.SetMandate(mandate); //then Assert.IsNotNull(actual); }
public async Task <IHttpActionResult> PostMandate(MandateModel model) { try { //1. Authorize Request if (!IsAuthorized()) { _logger.Warn($"{ nameof(this.PostMandate)} Unauthorised user"); return(Unauthorized()); } var content = JsonConvert.SerializeObject(model); _logger.Info($"{ nameof(this.PostMandate)} Payload : {content}"); //2. Set Mandate to BlockChain var result = await SmartContractManager.SetMandate(model); return(Ok(result)); } catch (Exception ex) { _logger.Error($"{ nameof(this.PostMandate)} Error : {ex}"); return(InternalServerError()); } }
public int?CalculFees(MandateModel md, string idRessource) { Resource rs = si.GetMany().Where(r => r.Id.Equals(idRessource)).FirstOrDefault(); //DateTime date1 = md.StartDate; //DateTime date2 = md.EndDate; //int nbrMonth1 = date1.Month; //int nbrYear1 = date1.Year; //int nbrMonth2 = date2.Month; //int nbrYear2 = date2.Year; //int Duree = ((nbrMonth2 - nbrMonth1) * 30) + ((nbrYear2 - nbrYear1) * 365); var Duree = (int)(md.EndDate - md.StartDate).TotalDays; return(Duree * ((int)rs.Salary)); }
public async Task <MandateModel> GetMandate(MandateAccountModel model) { //1. Create user object var user = new User { Email = model.Email, MobileNumber = model.MobileNumber }; var mandate = new MandateModel { Email = model.Email, MobileNumber = model.MobileNumber }; //2. Get Smart Meter Mandate var smartMet = await SmartContractService.GetSmartMandate(user); if (!string.IsNullOrEmpty(smartMet)) { var smartMandateType = JsonConvert.DeserializeObject <MandateType>(smartMet); mandate.SmartMeter = smartMandateType; } //3. Get Source Profile Mandate var smartPro = await SmartContractService.GetProfileMandate(user); if (!string.IsNullOrEmpty(smartPro)) { var proMandateType = JsonConvert.DeserializeObject <MandateType>(smartPro); mandate.SourceProfile = proMandateType; } //3. Get Trusted Party Mandate var trustPar = await SmartContractService.GetTrustedMandate(user); if (!string.IsNullOrEmpty(trustPar)) { var trustMandateType = JsonConvert.DeserializeObject <MandateType>(trustPar); mandate.SourceProfile = trustMandateType; } return(mandate); }
public MandateController() { mandateModels = new List <MandateModel>(); mandates = s.GetMandates(); foreach (var m in mandates) { var req = from p in si.GetMany() where p.Id == m.IdResource select p; var r = req.FirstOrDefault(); ResourceModel rm = new ResourceModel() { FirstName = r.FirstName, LastName = r.LastName, Salary = (int)r.Salary }; var reqe = from p in sii.GetMany() where p.Project_id == m.IdProject select p; var re = reqe.FirstOrDefault(); ProjectModel pm = new ProjectModel() { Name = re.Name }; MandateModel md = new MandateModel() { MandateId = m.MandateId, EndDate = m.EndDate, Fees = m.Fees, IdProject = m.IdProject, IdResource = m.IdResource, StartDate = m.StartDate, Resource = rm, Project = pm, Disponibility = m.Disponibility }; mandateModels.Add(md); if (md.StartDate >= System.DateTime.Today) { md.Disponibility = "available"; } else { md.Disponibility = "unavailable"; } } }
public ActionResult Edit([Bind(Include = "IdResource,IdProject,MandateId,StartDate,EndDate,Fees")] MandateModel mandateModel) { if (ModelState.IsValid) { var m = mandates.Where(e => e.MandateId == mandateModel.MandateId).FirstOrDefault(); m.EndDate = mandateModel.EndDate; m.Fees = mandateModel.Fees; m.IdProject = mandateModel.IdProject; m.IdResource = mandateModel.IdResource; m.StartDate = mandateModel.StartDate; s.UpdateMandate(m); s.Commit(); return(RedirectToAction("Index")); } //ViewBag.IdMandateHistory = new SelectList(db.MandateHistoryModels, "IdMandateHistory", "IdMandateHistory", mandateModel.IdMandateHistory); return(View(mandateModel)); }
public async Task <string> SetMandate(MandateModel model) { var mandate = new Mandate { Email = model.Email, MobileNumber = (string.IsNullOrEmpty(model.MobileNumber)) ? "" : model.MobileNumber, SmartActive = (model.SmartMeter != null) ? model.SmartMeter.Active : false, SmartStartDate = (model.SmartMeter != null) ? model.SmartMeter.StartDate : "", SmartEndDate = (model.SmartMeter != null) ? model.SmartMeter.EndDate : "", ProfileActive = (model.SourceProfile != null) ? model.SourceProfile.Active : false, ProfileStartDate = (model.SourceProfile != null) ? model.SourceProfile.StartDate : "", ProfileEndDate = (model.SourceProfile != null) ? model.SourceProfile.EndDate : "", TrustedPartyActive = (model.TrustedParty != null) ? model?.TrustedParty.Active : false, TrustedPartyStartDate = (model.TrustedParty != null) ? model.TrustedParty.StartDate : "", TrustedPartyEndDate = (model.TrustedParty != null) ? model.TrustedParty.EndDate : "" }; var response = await SmartContractService.SetMandate(mandate); return(response); }
// GET: Mandate/Create public ActionResult Create() { // ViewBag.IdMandateHistory = new SelectList(db.MandateHistoryModels, "IdMandateHistory", "IdMandateHistory"); MandateModel re = new MandateModel(); re.Resources = srs.GetMany().Select(c => new SelectListItem { Text = c.UserName, Value = c.Id, }); re.Projects = sii.GetMany().Select(cc => new SelectListItem { Text = cc.Name, Value = cc.Project_id.ToString(), }); return(View(re)); }
public ActionResult Create([Bind(Include = "IdResource,IdProject,MandateId,StartDate,EndDate,Fees")] MandateModel mandateModel) { if (ModelState.IsValid) { Mandate m = new Mandate() { MandateId = mandateModel.MandateId, IdMandateHistory = 1, EndDate = mandateModel.EndDate, Fees = CalculFees(mandateModel, mandateModel.IdResource), IdProject = mandateModel.IdProject, IdResource = mandateModel.IdResource, StartDate = mandateModel.StartDate, Disponibility = mandateModel.Disponibility }; s.AddMandate(m); //db.MandateModels.Add(mandateModel); s.Commit(); //MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); //SmtpClient client = new SmtpClient(); //client.Credentials = new NetworkCredential("*****@*****.**", "Espritsabrine100"); //client.Port = 25; //client.DeliveryMethod = SmtpDeliveryMethod.Network; //client.UseDefaultCredentials = false; //client.Host = "smtp.gmail.com"; //mail.Subject = "this is a test email."; //mail.Body = "this is my test email body"; //client.Send(mail); var req = from p in si.GetMany() where p.Id == mandateModel.IdResource select p; var r = req.FirstOrDefault(); MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(r.Email); mail.Subject = "Assignment to a mandate"; mail.IsBodyHtml = true; mail.Body = "<div style='width:80%;margin-left:10%;border:1.5px solid #1b1a19;border-radius:7px;background:-moz-linear-gradient(top,white 0%,white 55%,#d5e4f3 130%)'>" + "<img src = 'https://scontent.ftun6-1.fna.fbcdn.net/v/t1.0-1/p720x720/17629739_661947114149166_6086201923177778760_n.png?_nc_cat=103&_nc_ht=scontent.ftun6-1.fna&oh=b248a78916f16409356bdba4cf746f01&oe=5C73CBC5' style = 'width:40%;height:250;margin-left:5%' class='CToWUd'>" + "<div style = 'margin-left:7%' >" + "<h3> Welcome " + r.FirstName + " " + r.LastName + ",</h3>" + "<p>You are assigned to a new mandate, please check your account</p>" + "<h3>Mandate details :</h3>" + "<table>" + "<tbody>" + " <tr><td><b>Start date :</b></td><td>" + mandateModel.StartDate + "</td></tr>" + "<tr><td><b>End date:</b></td><td>" + mandateModel.EndDate + "</td></tr>" + " </tbody>" + " </table>" + " <p>" + " You can access to our website : <a href = 'https://www.levio.ca' style= 'color:#253c93;text-decoration:none' > www.levio.ca </a>" + "</p> " + "</div>" + "</div> "; SmtpServer.Port = 25; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Espritsabrine100"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); return(RedirectToAction("Index")); } // return(View(mandateModel)); }