public static CustomerAttachment CreateCustomerAttachment(string dataAreaId, global::System.Guid documentId, global::Microsoft.Dynamics.DataEntities.CustomerV3 customerAttachmentsEntity)
        {
            CustomerAttachment customerAttachment = new CustomerAttachment();

            customerAttachment.dataAreaId = dataAreaId;
            customerAttachment.DocumentId = documentId;
            if ((customerAttachmentsEntity == null))
            {
                throw new global::System.ArgumentNullException("customerAttachmentsEntity");
            }
            customerAttachment.CustomerAttachmentsEntity = customerAttachmentsEntity;
            return(customerAttachment);
        }
Exemple #2
0
        public IActionResult Update(CustomerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /**************** Updating Customer **************/

            var single = _context.Customers.Single(x => x.CustomerId == model.CustomerId);

            single.CustomerName       = model.CustomerName;
            single.NIC                = model.NIC;
            single.HomeAddress        = model.HomeAddress;
            single.HomeLandline       = model.HomeLandline;
            single.OfficeAddress      = model.OfficeAddress;
            single.OfficeLandline     = model.OfficeLandline;
            single.Mobile             = model.Mobile;
            single.OpeningBalance     = model.OpeningBalance;
            single.CurrentBalance     = model.CurrentBalance;
            single.LastCollectionDate = model.LastCollectionDate;

            var flag  = _context.SaveChanges();
            var cusId = single.CustomerId;


            /**************** Updating Customer Attachments and Saving **************/
            DeleteFiles(model.CustomerId);
            Miscellaneous.CreateFolder(_hostingEnvironment.WebRootPath + @"\files");
            IList <CustomerAttachmentViewModel> customerAttachmentList = model.CustomerAttachmentList;

            foreach (var item in customerAttachmentList)
            {
                string randName = DateTime.Now.ToString("MMddyyyyhhmmssfff") + "_" + new Random().Next(0, 10000).ToString("D6") + "_" + item.AttachmentName;
                string base64   = item.AttachmentFile.Split(",")[1];
                byte[] data     = Convert.FromBase64String(base64);
                string path     = _hostingEnvironment.WebRootPath + @"\files\" + randName;
                System.IO.File.WriteAllBytes(path, data.ToArray());
                CustomerAttachment customerAttachment = new CustomerAttachment()
                {
                    AttachmentName = item.AttachmentName,
                    AttachmentPath = randName,
                    CustomerId     = cusId,
                    MimeType       = item.AttachmentFile.Split(",")[0]
                };
                _context.CustomerAttachments.Add(customerAttachment);
                _context.SaveChanges();
            }

            return(Ok(true));
        }
Exemple #3
0
        public IActionResult Create(CustomerViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            /**************** Saving Customer **************/
            Customer customer = _mapper.Map <Customer>(model);

            customer.CurrentStatus = 1;
            customer.CreatedDate   = DateTime.Now;
            _context.Customers.Add(customer);
            var flag       = _context.SaveChanges();
            var customerId = customer.CustomerId;


            if (flag > 0)
            {
                /**************** Creating Customer Attachments and Saving **************/
                Miscellaneous.CreateFolder(_hostingEnvironment.WebRootPath + @"\files");
                IList <CustomerAttachmentViewModel> customerAttachmentList = model.CustomerAttachmentList;
                foreach (var item in customerAttachmentList)
                {
                    string randName = DateTime.Now.ToString("MMddyyyyhhmmssfff") + "_" + new Random().Next(0, 10000).ToString("D6") + "_" + item.AttachmentName;
                    string base64   = item.AttachmentFile.Substring(item.AttachmentFile.IndexOf(',') + 1);
                    byte[] data     = Convert.FromBase64String(base64);
                    string path     = _hostingEnvironment.WebRootPath + @"\files\" + randName;
                    System.IO.File.WriteAllBytes(path, data.ToArray());
                    CustomerAttachment customerAttachment = new CustomerAttachment()
                    {
                        AttachmentName = item.AttachmentName,
                        AttachmentPath = randName,
                        CustomerId     = customerId,
                        MimeType       = item.AttachmentFile.Split(",")[0]
                    };
                    _context.CustomerAttachments.Add(customerAttachment);
                    _context.SaveChanges();
                }
                return(Ok(true));
            }

            return(Ok(false));
        }