public async Task <IActionResult> Edit(int id, [Bind("FuelSupplierId,ContactId,Value,Id,Created,Modified,IsDeleted,ItemOrder")] SupplierContact supplierContact)
        {
            if (id != supplierContact.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplierContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SupplierContactExists(supplierContact.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ContactId"]      = new SelectList(_context.Contact, "Id", "DisplayName", supplierContact.ContactId);
            ViewData["FuelSupplierId"] = new SelectList(_context.FuelSupplier, "Id", "Name", supplierContact.FuelSupplierId);
            return(View(supplierContact));
        }
Esempio n. 2
0
        public ActionResult DeleteConfirmed(int id)
        {
            SupplierContact supplierContact = db.SupplierContacts.Find(id);

            db.SupplierContacts.Remove(supplierContact);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteContact(int contactid, int supplierid)
        {
            SupplierContact supplierContact = Db.SupplierContacts.Find(contactid);

            Db.SupplierContacts.Remove(supplierContact);
            Db.SaveChanges();
            return(RedirectToAction("Details", new { id = supplierid }));
        }
Esempio n. 4
0
        private void SaveContact()
        {
            contactManager = new ContactManager(this);
            contact        = new DataClasses.Contact();
            var originalContact = new DataClasses.Contact();

            if (!String.IsNullOrEmpty(Request["ContactId"]))
            {
                originalContact = contactManager.GetContact(Convert.ToInt32(Request["ContactId"]));
                contact.CopyPropertiesFrom(originalContact);
            }
            else
            {
                contact.UserId = User.Identity.UserId;
            }

            contact.CompanyId     = Company.CompanyId;
            contact.AddressComp   = ucAddress.AddressComp;
            contact.AddressNumber = ucAddress.AddressNumber;
            contact.PostalCode    = ucAddress.PostalCode;

            contact.CellPhone   = txtCellPhone.Text;
            contact.Email       = txtMail.Text;
            contact.Msn         = txtMsn.Text;
            contact.Name        = txtName.Text;
            contact.Observation = txtObservation.Text;
            contact.Phone       = txtPhone.Text;
            contact.Phone2      = txtPhone2.Text;
            contact.Sector      = txtSector.Text;
            contact.Skype       = txtSkype.Text;


            if (!String.IsNullOrEmpty(Request["ContactId"]))
            {
                contactManager.Update(originalContact, contact);
            }
            else
            {
                contactManager.Insert(contact);

                if (Session["CustomerId"] != null)
                {
                    var customerContact = new CustomerContact();
                    customerContact.CompanyId  = Company.CompanyId;
                    customerContact.CustomerId = Convert.ToInt32(Session["CustomerId"].ToString());
                    customerContact.ContactId  = contact.ContactId;
                    contactManager.InsertCustomerContact(customerContact);
                }
                else
                {
                    var supplierContact = new SupplierContact();
                    supplierContact.CompanyId  = Company.CompanyId;
                    supplierContact.SupplierId = Convert.ToInt32(Session["SupplierId"].ToString());
                    supplierContact.ContactId  = contact.ContactId;
                    contactManager.InsertSupplierContact(supplierContact);
                }
            }
        }
Esempio n. 5
0
    /// <summary>
    /// This method inserts a new SupplierContact
    /// </summary>
    private void InsertSupplierContact()
    {
        var supplierContact = new SupplierContact();

        supplierContact.CompanyId  = Company.CompanyId;
        supplierContact.SupplierId = Convert.ToInt32(Request["SupplierId"]);
        supplierContact.ContactId  = Convert.ToInt32(selContact.ContactId);
        ContactManager.InsertSupplierContact(supplierContact);
        grdContacts.DataBind();
    }
        public ActionResult AddContact(int supplierId)
        {
            Supplier supplier = Db.Suppliers.Find(supplierId);

            SupplierContact supplierContact = new SupplierContact();

            supplierContact.Supplier   = supplier;
            supplierContact.SupplierId = supplier.Id;

            return(View(supplierContact));
        }
Esempio n. 7
0
 public ActionResult Edit([Bind(Include = "SupplierContactId,SupplierContactName,SupplierContactTitle,SupplierContactCell,SupplierContactPhone,SupplierContactFax,SupplierContactEmail,Notes,SupplierId")] SupplierContact supplierContact)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplierContact).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.SupplierId = new SelectList(db.Suppliers, "SupplierId", "SupplierName", supplierContact.SupplierId);
     return(View(supplierContact));
 }
        public async Task <IActionResult> Create(Supplier supplier, IFormCollection collection)
        {
            var contacts      = collection["hddContacts"].ToString();
            var listContacts  = JsonConvert.DeserializeObject <List <lContacts> >(contacts).ToList();
            var coloniaId     = int.Parse(collection["ddColonia"].ToString());
            var colonia       = _context.Neighborhoods.Include(c => c.City).ThenInclude(s => s.State).ThenInclude(c => c.Country).FirstOrDefault(n => n.Id == coloniaId);
            var paymentMethod = _context.PaymentMethods.FirstOrDefault(p => p.Id == int.Parse(collection["PaymentMethod"].ToString()));
            var currency      = _context.Currencies.FirstOrDefault(p => p.Id == int.Parse(collection["Currency"].ToString()));
            var neighborhood  = _context.Neighborhoods.Include(i => i.City).ThenInclude(s => s.State).ThenInclude(c => c.Country).FirstOrDefault(i => i.Id == int.Parse(collection["ddColonia"].ToString()));
            //Create address
            var address = new Address()
            {
                Street         = collection["txtStreet"].ToString(),
                ExternalNumber = collection["txtExternalNumber"].ToString(),
                InternalNumber = collection["txtInternalNumber"].ToString(),
                Neighborhood   = neighborhood,
                Active         = true,
                Created        = DateTime.Now,
                CreatedBy      = UserLogged,
                Modified       = DateTime.Now,
                ModifiedBy     = UserLogged
            };

            //Create contacts
            foreach (var item in listContacts)
            {
                var contactType = _context.ContactTypes.FirstOrDefault(c => c.Id == item.ContactTypeId);
                var contact     = new SupplierContact()
                {
                    ContactName = item.ContactName,
                    ContactType = contactType,
                    Description = item.Description,
                    Created     = DateTime.Now,
                    CreatedBy   = UserLogged,
                    Modified    = DateTime.Now,
                    ModifiedBy  = UserLogged
                };
                supplier.AddContact(contact);
            }
            //Fill general data
            supplier.PaymentMethod = paymentMethod;
            supplier.Currency      = currency;
            supplier.Address       = address;
            supplier.Active        = true;
            supplier.Created       = DateTime.Now;
            supplier.CreatedBy     = UserLogged;
            supplier.Modified      = DateTime.Now;
            supplier.ModifiedBy    = UserLogged;
            _context.Add(supplier);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("FuelSupplierId,ContactId,Value,Id,Created,Modified,IsDeleted,ItemOrder")] SupplierContact supplierContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplierContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ContactId"]      = new SelectList(_context.Contact, "Id", "DisplayName", supplierContact.ContactId);
            ViewData["FuelSupplierId"] = new SelectList(_context.FuelSupplier, "Id", "Name", supplierContact.FuelSupplierId);
            return(View(supplierContact));
        }
 public ActionResult AddContact(SupplierContact supplierContact)
 {
     try
     {
         Db.SupplierContacts.Add(supplierContact);
         Db.SaveChanges();
         return(RedirectToAction("Details", new { id = supplierContact.SupplierId }));
     }
     catch
     {
         ViewBag.ErrorMessage = "Error occured while adding contact number.";
         return(View("Error"));
     }
 }
Esempio n. 11
0
        // GET: SupplierContacts/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierContact supplierContact = db.SupplierContacts.Find(id);

            if (supplierContact == null)
            {
                return(HttpNotFound());
            }
            return(View(supplierContact));
        }
Esempio n. 12
0
        /// <summary>
        /// Basic Insert Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="companyId"></param>
        /// <param name="supplierId"></param>
        public void AddContact(Contact entity, Int32 companyId, Int32 supplierId)
        {
            var contactManager = new ContactManager(this);

            entity.CompanyId = companyId;
            contactManager.Insert(entity);

            var scManager = new SuppliersContactManager(this);
            var sc        = new SupplierContact();

            sc.SupplierId = supplierId;
            sc.ContactId  = entity.ContactId;
            sc.CompanyId  = companyId;
            scManager.Insert(sc);
        }
Esempio n. 13
0
        /// <summary>
        /// Basic Delete Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="supplierId"></param>
        /// <param name="companyId"></param>
        public void RemoveContact(Contact entity, Int32 supplierId, Int32 companyId)
        {
            var scManager = new SuppliersContactManager(this);
            var sc        = new SupplierContact
            {
                SupplierId = supplierId,
                ContactId  = entity.ContactId
            };

            scManager.Delete(sc);

            var contactManager = new ContactManager(this);

            contactManager.Delete(entity);
        }
Esempio n. 14
0
        // GET: SupplierContacts/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierContact supplierContact = db.SupplierContacts.Find(id);

            if (supplierContact == null)
            {
                return(HttpNotFound());
            }
            ViewBag.SupplierId = new SelectList(db.Suppliers, "SupplierId", "SupplierName", supplierContact.SupplierId);
            return(View(supplierContact));
        }
        private void InsertSupplierContactLocation(SupplierContact contItem, List <Guid> locaGuidList)
        {
            var SCLitem = new SupplierContactLocation();

            SCLitem.SupplierContactLocationID = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]);
            SCLitem.SupplierContactID         = contItem.SupplierContactID;
            SCLitem.CreatedBy   = contItem.CreatedBy;
            SCLitem.CreatedDate = contItem.CreatedDate;
            SCLitem.UpdatedBy   = contItem.UpdatedBy;
            SCLitem.UpdatedDate = contItem.UpdatedDate;
            foreach (var locaGuid in locaGuidList)
            {
                SCLitem.SupplierLocationID = locaGuid;
                _supplierContactLocationService.Insert(SCLitem);
            }
        }
        private void InsertSupplierContactDepartment(SupplierContact contItem, List <Guid> depaGuidList)
        {
            var SCDitem = new SupplierContactDepartment();

            SCDitem.SupplierContactDepartmentID = PrimeActs.Service.IDGenerator.NewGuid(_serverCode[0]);
            SCDitem.SupplierContactID           = contItem.SupplierContactID;
            SCDitem.CreatedBy   = contItem.CreatedBy;
            SCDitem.CreatedDate = contItem.CreatedDate;
            SCDitem.UpdatedBy   = contItem.UpdatedBy;
            SCDitem.UpdatedDate = contItem.UpdatedDate;
            foreach (var depaGuid in depaGuidList)
            {
                SCDitem.SupplierDepartmentID = depaGuid;
                _supplierContactDepartmentService.Insert(SCDitem);
            }
        }
Esempio n. 17
0
        // Method to return a List of SupplierContacts. (T. Leslie)
        private static List <SupplierContact> GetSupplierContacts()
        {
            List <SupplierContact> suppliercontacts = new List <SupplierContact>();

            SqlConnection conn = TravelExpertsDB.GetConnection();

            // create a sql select statement
            string selectStatement =
                "SELECT SupplierContactId, SupplierId " +
                "FROM SupplierContacts";

            SqlCommand selectCommand = new SqlCommand(selectStatement, conn);

            try
            {
                conn.Open();// open connection

                SqlDataReader sr = selectCommand.ExecuteReader();

                while (sr.Read()) // product record exists
                {
                    SupplierContact suppliercontact = new SupplierContact();
                    suppliercontact.SupplierContactId = (int)sr["SupplierContactId"];
                    suppliercontact.SupplierId        = (int)sr["SupplierId"];
                    if (sr["SupplierId"] is DBNull)
                    {
                        suppliercontact.SupplierId = null;
                    }
                    else
                    {
                        suppliercontact.SupplierId = (int)(sr["SupplierId"]);
                    }

                    suppliercontacts.Add(suppliercontact);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(suppliercontacts);
        }
        private SupplierContact ApplyChanges(SupplierContactEditModel model)
        {
            var _obj = new SupplierContact();

            _obj.SupplierContactID = model.SupplierContactID;
            _obj.SupplierID        = model.SupplierID;
            _obj.ContactID         = SaveContact(model);
            _obj.SortOrder         = model.SortOrder; /////////////--- ??? --- !!!
            _obj.CreatedDate       = !string.IsNullOrEmpty(model.CreatedDate)
                ? DateTime.Parse(model.CreatedDate)
                : DateTime.Now;
            _obj.CreatedBy   = _principal.Id;
            _obj.UpdatedDate = DateTime.Now;
            _obj.UpdatedBy   = _principal.Id;
            _obj.IsActive    = true;
            return(_obj);
        }
        // GET: SupplierContact
        public ActionResult Index(int pageNo = 1, int id = 0, int supplierid = 0, string searchString = "")
        {
            var sup    = db.Suppliers.Where(a => a.Name.Contains(searchString)).FirstOrDefault();
            var supcon = from a in db.SupplierContacts
                         select a;

            if (!String.IsNullOrEmpty(searchString))
            {
                supcon = db.SupplierContacts.Where(s => s.SupplierId.Equals(sup.Id));
            }


            var model = new SupplierContact();

            if (id > 0)
            {
                model = db.SupplierContacts.Find(id);
            }
            BindList(pageNo, supplierid, supcon.ToList());
            ViewBag.Suppliers = new SelectList(db.Suppliers.ToList(), "Id", "Name", supplierid);
            return(View(model));
        }
        public JsonResult Import(HttpPostedFileBase file)
        {
            DataSet         ds = file.ToDataSet();
            SupplierContact item;

            if (ds != null)
            {
                foreach (DataTable dt in ds.Tables)
                {
                    foreach (DataRow r in dt.Rows)
                    {
                        item = new SupplierContact()
                        {
                            Name = r[1].ToString()
                        };
                        db.SupplierContacts.Add(item);
                    }
                }
                db.SaveChanges();
            }
            return(Json(new { success = true }));
        }
Esempio n. 21
0
        public SupplierInfo GetSupplierInfo(string suppliercode)
        {
            SupplierInfo objSupplierInfo = new SupplierInfo();
            List <SupplierAttachment> objSupplierAttachment = new List <SupplierAttachment>();
            List <SupplierBusiness>   objSupplierBusiness   = new List <SupplierBusiness>();
            List <SupplierContact>    objSupplierContact    = new List <SupplierContact>();
            string vSupplierText   = @"SELECT [SupplierCode]
                                      ,[SupplierID]
                                      ,[SupplierName]
                                      ,[Email]
                                      ,[MobileNumber]
                                      ,[EnlistmentDate]
                                      ,[SupplierAddress]
                                      ,[AlternateEmail]
                                      ,[ZipCode]
                                      ,[Fax]
                                      ,[IsApproved]
                                      ,[ApprovalAction]
                                  FROM [LSP_PMS_SupplierInfo] where  SupplierCode = '" + suppliercode + "'";
            string vAttachmentText = @"SELECT [AttachmentCode]
                                              ,[SupplierCode]
                                              ,[AttachmentName]
                                              ,[CertificateNumber]
                                              ,[IssueDate]
                                              ,[ExpiryDate]
                                              ,[FileLocationPath]
                                              ,[Remarks]
                                          FROM [LSP_PMS_SupplierDocuments] where  SupplierCode = '" + suppliercode + "'";

            string        vContactText  = @"SELECT [ContactPersonCode]
                                          ,[SupplierCode]
                                          ,[ContactName]
                                          ,[JobRole]
                                          ,[Email]
                                          ,[MobileNumber]
                                          ,[Designation]
                                          ,[TelephoneNumber]
                                      FROM [LSP_PMS_SupplierContact] where  SupplierCode = '" + suppliercode + "'";
            string        vBusinessText = @"SELECT [SupplierCode]
                                              ,[BusinessTypeCode]
                                              ,filename
                                          FROM [LSP_PMS_SupplierBusiness]  b
                                           join general_codefile f on b.[BusinessTypeCode]=f.filecode
                                           where  SupplierCode = '" + suppliercode + "'";
            SqlConnection connection    = _supplierDbContext.GetConn();

            connection.Open();
            SqlCommand objDbCommand = new SqlCommand(vSupplierText, connection);

            using (SqlDataReader dr = objDbCommand.ExecuteReader())
            {
                if (dr.Read())
                {
                    objSupplierInfo = new SupplierInfo();
                    objSupplierInfo.SupplierCode_PK = dr["SupplierCode"].ToString();
                    objSupplierInfo.SupplierID      = dr["SupplierID"].ToString();
                    objSupplierInfo.SupplierName    = dr["SupplierName"].ToString();
                    objSupplierInfo.Email           = dr["Email"].ToString();
                    objSupplierInfo.MobileNumber    = dr["MobileNumber"].ToString();
                    objSupplierInfo.EnlistmentDate  = dr.GetDateTime(dr.GetOrdinal("EnlistmentDate")).ToString("dd-MM-yyyy");
                    objSupplierInfo.SupplierAddress = dr["SupplierAddress"].ToString();
                    objSupplierInfo.AlternateEmail  = dr["AlternateEmail"].ToString();
                    objSupplierInfo.ZipCode         = dr["ZipCode"].ToString();
                    objSupplierInfo.Fax             = dr["Fax"].ToString();
                    objSupplierInfo.IsApproved      = Convert.ToInt16(dr["IsApproved"].ToString());
                    objSupplierInfo.ApprovalAction  = Convert.ToInt16(dr["ApprovalAction"].ToString());
                }
            }
            SqlCommand objDbCommandAttachment = new SqlCommand(vAttachmentText, connection);

            using (SqlDataReader dr = objDbCommandAttachment.ExecuteReader())
            {
                while (dr.Read())
                {
                    SupplierAttachment supplierAttachment = new SupplierAttachment();
                    supplierAttachment.AttachmentCode_PK = dr["AttachmentCode"].ToString();
                    supplierAttachment.SupplierCode_FK   = dr["SupplierCode"].ToString();
                    supplierAttachment.AttachmentName    = dr["AttachmentName"].ToString();
                    supplierAttachment.CertificateNumber = dr["CertificateNumber"].ToString();
                    if (!string.IsNullOrEmpty(dr["IssueDate"].ToString()))
                    {
                        supplierAttachment.IssueDate = dr.GetDateTime(dr.GetOrdinal("IssueDate")).ToString("dd-MM-yyyy");
                    }
                    if (!string.IsNullOrEmpty(dr["ExpiryDate"].ToString()))
                    {
                        supplierAttachment.ExpiryDate = dr.GetDateTime(dr.GetOrdinal("ExpiryDate")).ToString("dd-MM-yyyy");
                    }
                    supplierAttachment.FileLocationPath = dr["FileLocationPath"].ToString();
                    supplierAttachment.Remarks          = dr["Remarks"].ToString();

                    objSupplierAttachment.Add(supplierAttachment);
                }
            }
            SqlCommand objDbCommandBusiness = new SqlCommand(vBusinessText, connection);

            using (SqlDataReader dr = objDbCommandBusiness.ExecuteReader())
            {
                while (dr.Read())
                {
                    SupplierBusiness supplierBusiness = new SupplierBusiness();
                    supplierBusiness.SupplierCode_FK     = dr["SupplierCode"].ToString();
                    supplierBusiness.BusinessTypeCode_PK = Convert.ToInt16(dr["BusinessTypeCode"].ToString());
                    supplierBusiness.filename_VW         = dr["filename"].ToString();
                    objSupplierBusiness.Add(supplierBusiness);
                }
            }
            SqlCommand objDbCommandContact = new SqlCommand(vContactText, connection);

            using (SqlDataReader dr = objDbCommandContact.ExecuteReader())
            {
                while (dr.Read())
                {
                    SupplierContact supplierContact = new SupplierContact();
                    supplierContact.SupplierCode_FK      = dr["SupplierCode"].ToString();
                    supplierContact.ContactPersonCode_PK = dr["ContactPersonCode"].ToString();
                    supplierContact.ContactName          = dr["ContactName"].ToString();
                    supplierContact.JobRole         = dr["JobRole"].ToString();
                    supplierContact.Email           = dr["Email"].ToString();
                    supplierContact.MobileNumber    = dr["MobileNumber"].ToString();
                    supplierContact.Designation     = dr["Designation"].ToString();
                    supplierContact.TelephoneNumber = dr["TelephoneNumber"].ToString();
                    objSupplierContact.Add(supplierContact);
                }
            }

            objSupplierInfo.SupplierAttachmentList_VW = objSupplierAttachment;
            objSupplierInfo.SupplierBusinessList_VW   = objSupplierBusiness;
            objSupplierInfo.SupplierContactList_VW    = objSupplierContact;
            return(objSupplierInfo);
        }
Esempio n. 22
0
        public async Task <IActionResult> OnPostAsync()
        {
            ReturnUrl = Url.Content("~/");
            if (ModelState.IsValid)
            {
                if (User.Identity.IsAuthenticated)
                {
                    await _signInManager.SignOutAsync();

                    _logger.LogInformation("User logged out.");
                }
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var UserManager = _serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                    var RoleManager = _serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();

                    var roleResult = await RoleManager.FindByNameAsync("Supplier");

                    if (roleResult == null)
                    {
                        roleResult = new ApplicationRole("Supplier");
                        await RoleManager.CreateAsync(roleResult);
                    }
                    await UserManager.AddToRoleAsync(user, "Supplier");

                    FuelSupplier fuelSupplier = new FuelSupplier();
                    fuelSupplier.UserId    = user.Id;
                    fuelSupplier.Name      = Input.Name;
                    fuelSupplier.CountryId = Input.CountryId;
                    fuelSupplier.IsMiddler = Input.IsMiddler;

                    if (Input.file != null)
                    {
                        FileInfo fi          = new FileInfo(Input.file.FileName);
                        var      newFilename = "P" + fuelSupplier.Id + "_" + string.Format("{0:d}",
                                                                                           (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                        var webPath = _hostingEnvironment.WebRootPath;
                        var path    = Path.Combine("", webPath + @"\uploads\suppliers\" + newFilename);

                        var pathToSave = @"/uploads/suppliers/" + newFilename;

                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await Input.file.CopyToAsync(stream);
                        }
                        fuelSupplier.ImageUrl = pathToSave;
                    }

                    SupplierContact supplierContact1 = new SupplierContact();
                    supplierContact1.ContactId = 3;
                    supplierContact1.Value     = Input.CompanyWebSite;

                    SupplierContact supplierContact2 = new SupplierContact();
                    supplierContact2.ContactId = 18;
                    supplierContact2.Value     = _context.Country.Find(Input.CountryId) != null?
                                                 _context.Country.Find(Input.CountryId).Name : "";

                    fuelSupplier.SupplierContact = new List <SupplierContact>();
                    fuelSupplier.SupplierContact.Add(supplierContact1);
                    fuelSupplier.SupplierContact.Add(supplierContact2);

                    SupplierContactPerson supplierContactPerson = new SupplierContactPerson();
                    supplierContactPerson.JobTitle = Input.Position;
                    supplierContactPerson.Name     = Input.Name;
                    SupplierContactPersonContact supplierContactPersonContact = new SupplierContactPersonContact();
                    supplierContactPersonContact.ContactId             = 7;
                    supplierContactPersonContact.Value                 = Input.Email;
                    supplierContactPerson.SupplierContactPersonContact = new List <SupplierContactPersonContact>();
                    supplierContactPerson.SupplierContactPersonContact.Add(supplierContactPersonContact);

                    fuelSupplier.SupplierContactPerson = new List <SupplierContactPerson>();
                    fuelSupplier.SupplierContactPerson.Add(supplierContactPerson);

                    _context.FuelSupplier.Add(fuelSupplier);
                    _context.SaveChanges();

                    var contentAppName = _context.ContentManagement.Where(cm => cm.Name == "app_name")
                                         .FirstOrDefault();
                    string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName;

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    EmailBodyDefaultParams emailBodyDefaultParams = _context.EmailBodyDefaultParams
                                                                    .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault();
                    string body = EmailSender.CreateEmailBody(emailBodyDefaultParams);
                    body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl));
                    var simpleResponse = EmailSender.SendEmail(Input.Email, AppName, body);
                    TempData.Set("Toast", simpleResponse);
                    return(LocalRedirect(ReturnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Esempio n. 23
0
 /// <summary>
 /// This method inserts an relationship between supplier and contact
 /// </summary>
 /// <param name="customerContact"></param>
 public void InsertSupplierContact(SupplierContact supplierContact)
 {
     DbContext.SupplierContacts.InsertOnSubmit(supplierContact);
     DbContext.SubmitChanges();
 }
 // GET: SupplierContact/Edit/5
 public ActionResult Edit(SupplierContact model, int pageNo = 1)
 {
     db.Entry(model).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }
Esempio n. 25
0
        private void SaveContact()
        {
            contactManager = new ContactManager(this);
            contact = new DataClasses.Contact();
            var originalContact = new DataClasses.Contact();

            if (!String.IsNullOrEmpty(Request["ContactId"]))
            {
                originalContact = contactManager.GetContact(Convert.ToInt32(Request["ContactId"]));
                contact.CopyPropertiesFrom(originalContact);
            }
            else contact.UserId = User.Identity.UserId;

            contact.CompanyId = Company.CompanyId;
            contact.AddressComp = ucAddress.AddressComp;
            contact.AddressNumber = ucAddress.AddressNumber;
            contact.PostalCode = ucAddress.PostalCode;

            contact.CellPhone = txtCellPhone.Text;
            contact.Email = txtMail.Text;
            contact.Msn = txtMsn.Text;
            contact.Name = txtName.Text;
            contact.Observation = txtObservation.Text;
            contact.Phone = txtPhone.Text;
            contact.Phone2 = txtPhone2.Text;
            contact.Sector = txtSector.Text;
            contact.Skype = txtSkype.Text;


            if (!String.IsNullOrEmpty(Request["ContactId"]))
                contactManager.Update(originalContact, contact);
            else
            {
                contactManager.Insert(contact);

                if (Session["CustomerId"] != null)
                {
                    var customerContact = new CustomerContact();
                    customerContact.CompanyId = Company.CompanyId;
                    customerContact.CustomerId = Convert.ToInt32(Session["CustomerId"].ToString());
                    customerContact.ContactId = contact.ContactId;
                    contactManager.InsertCustomerContact(customerContact);
                }
                else
                {
                    var supplierContact = new SupplierContact();
                    supplierContact.CompanyId = Company.CompanyId;
                    supplierContact.SupplierId = Convert.ToInt32(Session["SupplierId"].ToString());
                    supplierContact.ContactId = contact.ContactId;
                    contactManager.InsertSupplierContact(supplierContact);
                }
            }
        }
        public async Task <JsonResult> SupplierRegister([FromBody] SupplierRegisterModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (User.Identity.IsAuthenticated)
                    {
                        await SignInManager.SignOutAsync();

                        Serilog.Log.Information("User logged out.");
                    }
                    var user = new ApplicationUser {
                        UserName = model.Email, Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        Serilog.Log.Information("User created a new account with password.");


                        var roleResult = await RoleManager.FindByNameAsync("Supplier");

                        if (roleResult == null)
                        {
                            roleResult = new ApplicationRole()
                            {
                                Name = "Supplier"
                            };
                            await RoleManager.CreateAsync(roleResult);
                        }
                        await UserManager.AddToRoleAsync(user, "Supplier");

                        FuelSupplier fuelSupplier = new FuelSupplier();
                        fuelSupplier.UserId    = user.Id;
                        fuelSupplier.Name      = model.Name;
                        fuelSupplier.CountryId = model.CountryId;
                        fuelSupplier.IsMiddler = model.IsMiddler;

                        if (model.file != null)
                        {
                            FileInfo fi          = new FileInfo(model.file.FileName);
                            var      newFilename = "P" + fuelSupplier.Id + "_" + string.Format("{0:d}",
                                                                                               (DateTime.Now.Ticks / 10) % 100000000) + fi.Extension;
                            var webPath = _hostingEnvironment.WebRootPath;
                            var path    = Path.Combine("", webPath + @"\uploads\suppliers\" + newFilename);

                            var pathToSave = @"/uploads/suppliers/" + newFilename;

                            using (var stream = new FileStream(path, FileMode.Create))
                            {
                                await model.file.CopyToAsync(stream);
                            }
                            fuelSupplier.ImageUrl = pathToSave;
                        }

                        SupplierContact supplierContact1 = new SupplierContact();
                        supplierContact1.ContactId = 3;
                        supplierContact1.Value     = model.CompanyWebSite;

                        SupplierContact supplierContact2 = new SupplierContact();
                        supplierContact2.ContactId = 18;
                        supplierContact2.Value     = db.Country.Find(model.CountryId) != null?
                                                     db.Country.Find(model.CountryId).Name : "";

                        fuelSupplier.SupplierContact = new List <SupplierContact>();
                        fuelSupplier.SupplierContact.Add(supplierContact1);
                        fuelSupplier.SupplierContact.Add(supplierContact2);

                        SupplierContactPerson supplierContactPerson = new SupplierContactPerson();
                        supplierContactPerson.JobTitle = model.Position;
                        supplierContactPerson.Name     = model.Name;
                        SupplierContactPersonContact supplierContactPersonContact = new SupplierContactPersonContact();
                        supplierContactPersonContact.ContactId             = 7;
                        supplierContactPersonContact.Value                 = model.Email;
                        supplierContactPerson.SupplierContactPersonContact = new List <SupplierContactPersonContact>();
                        supplierContactPerson.SupplierContactPersonContact.Add(supplierContactPersonContact);

                        fuelSupplier.SupplierContactPerson = new List <SupplierContactPerson>();
                        fuelSupplier.SupplierContactPerson.Add(supplierContactPerson);

                        db.FuelSupplier.Add(fuelSupplier);
                        db.SaveChanges();

                        var contentAppName = db.ContentManagement.Where(cm => cm.Name == "app_name")
                                             .FirstOrDefault();
                        string AppName = contentAppName == null ? "Fuel Services" : contentAppName.DisplayName;

                        var token = await UserManager.GenerateEmailConfirmationTokenAsync(user);

                        byte[] tokenGeneratedBytes = Encoding.UTF8.GetBytes(token);
                        var    code = WebEncoders.Base64UrlEncode(tokenGeneratedBytes);

                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { userId = user.Id, code = code },
                            protocol: Request.Scheme);

                        EmailBodyDefaultParams emailBodyDefaultParams = db.EmailBodyDefaultParams
                                                                        .Where(e => e.EmailTypeName == "confirm_mail").FirstOrDefault();
                        string body = EmailSender.CreateEmailBody(emailBodyDefaultParams);
                        body = body.Replace("{callbackurl}", HtmlEncoder.Default.Encode(callbackUrl));
                        var simpleResponse = EmailSender.SendEmail(model.Email, AppName, body);
                        //var token = GetTokenForUser(user);
                        return(new JsonResult(new Response <bool>(Constants.SUCCESS_CODE, true, simpleResponse.Message)));
                    }
                    else
                    {
                        string errors = "";
                        foreach (var error in result.Errors)
                        {
                            errors += error;
                        }
                        Serilog.Log.Error("Register Supplier", model.Email, errors);
                    }
                }

                else
                {
                    return(new JsonResult(new Response <bool>(Constants.INVALID_INPUT_CODE, false, Constants.INVALID_INPUT)));
                }
            }
            catch (Exception e)
            {
                Serilog.Log.Error(e, Constants.LogTemplates.LOGIN_ERROR_EX, model.Email);
                return(new JsonResult(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, GetExceptionMessage(e))));
            }

            return(new JsonResult(new Response <bool>(Constants.SOMETHING_WRONG_CODE, false, Constants.SOMETHING_WRONG)));
        }
Esempio n. 27
0
 /// <summary>
 /// This method inserts a new record in the table.
 /// Change this method to alter how records are inserted.
 /// </summary>
 /// <param name=entity>entity</param>
 public void Insert(SupplierContact entity)
 {
     DbContext.SupplierContacts.InsertOnSubmit(entity);
     DbContext.SubmitChanges();
 }
Esempio n. 28
0
 /// <summary>
 /// This method updates a record in the table.
 /// Change this method to alter how records are updated.
 /// </summary>
 /// <param name=original_entity>original_entity</param>
 /// <param name=entity>entity</param>
 public void Update(SupplierContact original_entity, SupplierContact entity)
 {
     DbContext.SupplierContacts.Attach(original_entity);
     DbContext.SubmitChanges();
 }
        /// <summary>
        /// Basic Delete Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="supplierId"></param>
        /// <param name="companyId"></param>
        public void RemoveContact(Contact entity, Int32 supplierId, Int32 companyId)
        {
            var scManager = new SuppliersContactManager(this);
            var sc = new SupplierContact
                         {
                             SupplierId = supplierId,
                             ContactId = entity.ContactId
                         };
            scManager.Delete(sc);

            var contactManager = new ContactManager(this);
            contactManager.Delete(entity);
        }
        /// <summary>
        /// Basic Insert Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="companyId"></param>
        /// <param name="supplierId"></param>
        public void AddContact(Contact entity, Int32 companyId, Int32 supplierId)
        {
            var contactManager = new ContactManager(this);
            entity.CompanyId = companyId;
            contactManager.Insert(entity);

            var scManager = new SuppliersContactManager(this);
            var sc = new SupplierContact();
            sc.SupplierId = supplierId;
            sc.ContactId = entity.ContactId;
            sc.CompanyId = companyId;
            scManager.Insert(sc);
        }
 // GET: SupplierContact/Create
 public ActionResult Create(SupplierContact model, int pageNo = 1)
 {
     db.SupplierContacts.Add(model);
     db.SaveChanges();
     return(RedirectToAction("Index", new { PageNo = pageNo }));
 }
 /// <summary>
 /// This method inserts an relationship between supplier and contact
 /// </summary>
 /// <param name="customerContact"></param>
 public void InsertSupplierContact(SupplierContact supplierContact)
 {
     DbContext.SupplierContacts.InsertOnSubmit(supplierContact);
     DbContext.SubmitChanges();
 }
Esempio n. 33
0
 /// <summary>
 /// This method deletes a record in the table.
 /// Change this method to alter how records are deleted.
 /// </summary>
 /// <param name=entity>entity</param>
 public void Delete(SupplierContact entity)
 {
     DbContext.SupplierContacts.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
Esempio n. 34
0
    /// <summary>
    /// This method inserts a new SupplierContact
    /// </summary>
    private void InsertSupplierContact()
    {
        var supplierContact = new SupplierContact();

        supplierContact.CompanyId = Company.CompanyId;
        supplierContact.SupplierId = Convert.ToInt32(Request["SupplierId"]);
        supplierContact.ContactId = Convert.ToInt32(selContact.ContactId);
        ContactManager.InsertSupplierContact(supplierContact);
        grdContacts.DataBind();
    }