Beispiel #1
0
        public VisitorDetail Get(string Mobile, int SocId)
        {
            try
            {
                var context = new NestinDBEntities();
                var guest   = (from g in context.VisitorDetails
                               where g.VisitorMobileNo == Mobile && g.SocietyId == SocId
                               select g).FirstOrDefault();

                if (guest == null)
                {
                    guest = new VisitorDetail
                    {
                        VisitorName     = "NoUser",
                        VisitorAddress  = "NoUser",
                        VisitorMobileNo = "NoUser",
                        id = 0
                    };
                }
                return(guest);
            }
            catch (Exception ex)
            {
                Log.log(" Get Guest has error at: " + DateTime.Now.ToString() + " " + ex.Message);
                return(null);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> AddVisitorDetail([Bind("VisitorDetailID,Name,Address,ContactNo,File")] VisitorDetail personalDetail)
        {
            using (var memoryStream = new MemoryStream())
            {
                await personalDetail.File.FormFile.CopyToAsync(memoryStream);

                string photoname = personalDetail.File.FormFile.FileName;
                personalDetail.Extension = Path.GetExtension(photoname);
                if (!".jpg.jpeg.png.gif.bmp".Contains(personalDetail.Extension.ToLower()))
                {
                    ModelState.AddModelError("File.FormFile", "Invalid Format of Image Given.");
                }
                else
                {
                    ModelState.Remove("Extension");
                }
            }
            ModelState.Remove("UserID");
            if (ModelState.IsValid)
            {
                personalDetail.UserID = _userManager.GetUserName(this.User);
                _context.Add(personalDetail);
                await _context.SaveChangesAsync();

                await _context.SaveChangesAsync();

                var uploadsRootFolder = Path.Combine(_environment.WebRootPath, "person");
                if (!Directory.Exists(uploadsRootFolder))
                {
                    Directory.CreateDirectory(uploadsRootFolder);
                }
                string filename = personalDetail.VisitorDetailID + personalDetail.Extension;
                var    filePath = Path.Combine(uploadsRootFolder, filename);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await personalDetail.File.FormFile.CopyToAsync(fileStream).ConfigureAwait(false);
                }
                return(RedirectToAction(nameof(MyDetails)));
            }
            return(View(personalDetail));
        }
Beispiel #3
0
        public HttpResponseMessage Post([FromBody] VisitorEntry value)
        {
            String resp = "{\"Response\":\"Undefine\"}";

            var ctx = new NestinDBEntities();

            using (var dbContextTransaction = ctx.Database.BeginTransaction())
            {
                try
                {
                    Random r    = new Random();
                    var    code = 0;

                    do
                    {
                        code = r.Next(1000, 9999);
                    } while (IsCodeInUse(code.ToString()));

                    String mobile = value.VisitorMobile;
                    if (mobile.Length > 10)
                    {
                        mobile = mobile.Substring(mobile.Length - 10, mobile.Length);
                    }

                    if (value.VisitorId == 0)
                    {
                        VisitorDetail guest = new VisitorDetail();
                        guest.VisitorMobileNo = mobile;
                        guest.VisitorName     = value.VisitorName;
                        guest.VisitorAddress  = value.VisitorAddress;
                        guest.SocietyId       = value.SocietyId;
                        guest.VisitorImage    = value.VisitorImage;
                        var c = ctx.VisitorDetails;
                        c.Add(guest);
                        ctx.SaveChanges();
                        value.VisitorId = guest.id;
                    }

                    if (value.VisitorId > 0)
                    {
                        ctx.VisitorRequests.Add(new VisitorRequest
                        {
                            VisitorId    = value.VisitorId,
                            VisitPurpose = value.VisitPurpose,
                            StartTime    = DateTime.ParseExact(value.StartTime, "yyyy-MM-ddTHH:mm:ss.SSSZ", System.Globalization.CultureInfo.InvariantCulture),
                            EndTime      = DateTime.ParseExact(value.EndTime, "yyyy-MM-ddTHH:mm:ss.SSSZ", System.Globalization.CultureInfo.InvariantCulture),

                            SecurityCode = code.ToString(),
                            SocietyId    = value.SocietyId,
                            ResId        = value.ResID,
                            Flat         = value.FlatNumber
                        });
                    }

                    ctx.SaveChanges();

                    dbContextTransaction.Commit();
                    var strMessage = "Code for Entry in Flat : " + value.FlatNumber + " is " + code.ToString();
                    VisitorNotification visitorNotification = new VisitorNotification(ctx, value.HostMobile);
                    var result = visitorNotification.NotifyVisitor(strMessage, value.VisitorMobile);


                    resp = "{\"Response\":\"Ok\"}";
                }
                //Exception ex
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Log.log("api/Profile Failed to Add User : Property-" + validationError.PropertyName + "  Error- " + validationError.ErrorMessage + "  At " + DateTime.Now.ToString());
                        }
                    }
                    dbContextTransaction.Rollback();
                    resp = "{\"Response\":\"Fail\"}";
                }
                catch (Exception ex)
                {
                    Log.log("api/Profile Failed to Add User Error- " + ex.Message + "  At " + DateTime.Now.ToString());

                    dbContextTransaction.Rollback();
                    resp = "{\"Response\":\"Fail\"}";
                }
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
            return(response);
        }